diff --git a/flatisfy/web/app.py b/flatisfy/web/app.py index f5ba19e..f0a66af 100644 --- a/flatisfy/web/app.py +++ b/flatisfy/web/app.py @@ -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")) diff --git a/flatisfy/web/routes/api.py b/flatisfy/web/routes/api.py index 3caff1e..dae22fa 100644 --- a/flatisfy/web/routes/api.py +++ b/flatisfy/web/routes/api.py @@ -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): 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))