Browse Source

Add import API

master
Gautier P 2 years ago
parent
commit
711590b809
  1. 1
      flatisfy/web/app.py
  2. 22
      flatisfy/web/routes/api.py

1
flatisfy/web/app.py

@ -96,6 +96,7 @@ def get_app(config): @@ -96,6 +96,7 @@ def get_app(config):
)
app.route("/api/v1/metadata", ["GET", "OPTIONS"], api_routes.metadata_v1)
app.route("/api/v1/import", ["GET", "OPTIONS"], api_routes.import_v1)
# Index
app.route("/", "GET", lambda: _serve_static_file("index.html"))

22
flatisfy/web/routes/api.py

@ -16,6 +16,7 @@ import vobject @@ -16,6 +16,7 @@ import vobject
import flatisfy.data
from flatisfy.models import flat as flat_model
from flatisfy.models.postal_code import PostalCode
from flatisfy import cmds
FILTER_RE = re.compile(r"filter\[([A-z0-9_]+)\]")
@ -496,3 +497,24 @@ def metadata_v1(config): @@ -496,3 +497,24 @@ def metadata_v1(config):
return {"data": {"last_update": last_update}}
except Exception as exc: # pylint: disable= broad-except
return JSONError(500, str(exc))
def import_v1(config):
"""
API v1 import new flats.
Example::
GET /api/v1/import
:return: The new flats.
"""
if bottle.request.method == "OPTIONS":
# CORS
return {}
try:
flats_id = cmds.import_and_filter(config, False, True)
return {"flats": flats_id}
except Exception as exc: # pylint: disable= broad-except
return JSONError(500, str(exc))

Loading…
Cancel
Save