Add import API

This commit is contained in:
Gautier P 2021-01-26 17:31:04 +01:00
parent a92db5e8ee
commit 711590b809
2 changed files with 23 additions and 0 deletions

View File

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

View File

@ -16,6 +16,7 @@ import vobject
import flatisfy.data import flatisfy.data
from flatisfy.models import flat as flat_model from flatisfy.models import flat as flat_model
from flatisfy.models.postal_code import PostalCode from flatisfy.models.postal_code import PostalCode
from flatisfy import cmds
FILTER_RE = re.compile(r"filter\[([A-z0-9_]+)\]") FILTER_RE = re.compile(r"filter\[([A-z0-9_]+)\]")
@ -496,3 +497,24 @@ def metadata_v1(config):
return {"data": {"last_update": last_update}} return {"data": {"last_update": last_update}}
except Exception as exc: # pylint: disable= broad-except except Exception as exc: # pylint: disable= broad-except
return JSONError(500, str(exc)) 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))