forked from edward/owl-map
Compare commits
2 commits
add-versio
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ea2b3c18d8 | |||
| 0d2cfd56cb |
4 changed files with 54 additions and 15 deletions
35
create_db.py
Executable file
35
create_db.py
Executable file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from sqlalchemy.schema import CreateIndex, CreateTable
|
||||||
|
|
||||||
|
from matcher import database, model
|
||||||
|
|
||||||
|
DB_URL = "postgresql:///matcher"
|
||||||
|
database.init_db(DB_URL)
|
||||||
|
|
||||||
|
|
||||||
|
def create_db():
|
||||||
|
model.Base.metadata.create_all(database.session.get_bind())
|
||||||
|
|
||||||
|
|
||||||
|
def print_create_table(classes):
|
||||||
|
database.init_db(DB_URL)
|
||||||
|
|
||||||
|
engine = database.session.get_bind()
|
||||||
|
|
||||||
|
for cls in classes:
|
||||||
|
sql = str(CreateTable(cls.__table__).compile(engine))
|
||||||
|
print(sql.strip() + ";")
|
||||||
|
|
||||||
|
for index in cls.__table__.indexes:
|
||||||
|
sql = str(CreateIndex(index).compile(engine))
|
||||||
|
print(sql.strip() + ";")
|
||||||
|
|
||||||
|
|
||||||
|
# print_create_table([model.ItemIsA])
|
||||||
|
# print_create_table([model.EditSession])
|
||||||
|
# print_create_table([model.Changeset, model.ChangesetEdit, model.SkipIsA])
|
||||||
|
# print_create_table([model.User])
|
||||||
|
# print_create_table([model.Extract])
|
||||||
|
|
||||||
|
create_db()
|
||||||
|
|
@ -31,6 +31,8 @@ def lookup_with_params(**kwargs: str) -> list[Hit]:
|
||||||
r = requests.get(url, params=params, headers=user_agent_headers())
|
r = requests.get(url, params=params, headers=user_agent_headers())
|
||||||
if r.status_code == 500:
|
if r.status_code == 500:
|
||||||
raise SearchError
|
raise SearchError
|
||||||
|
if r.status_code == 403:
|
||||||
|
raise SearchError("Nominatim returned 403 Forbidden")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reply: list[Hit] = json.loads(r.text, object_pairs_hook=OrderedDict)
|
reply: list[Hit] = json.loads(r.text, object_pairs_hook=OrderedDict)
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
flask==3.0.3
|
flask
|
||||||
-e git+https://github.com/maxcountryman/flask-login.git@26d12eaa99a18fc91e662ef0c8466245b8865c1c#egg=Flask-Login
|
-e git+https://github.com/maxcountryman/flask-login.git#egg=Flask-Login
|
||||||
GeoIP==1.3.2
|
GeoIP
|
||||||
lxml==5.3.0
|
lxml
|
||||||
maxminddb==2.6.2
|
maxminddb
|
||||||
requests==2.32.3
|
requests
|
||||||
sqlalchemy==2.0.32
|
sqlalchemy
|
||||||
requests_oauthlib==2.0.0
|
requests_oauthlib
|
||||||
geoalchemy2==0.15.2
|
geoalchemy2
|
||||||
simplejson==3.19.3
|
simplejson
|
||||||
user_agents==2.2.0
|
user_agents
|
||||||
num2words==0.5.13
|
num2words
|
||||||
psycopg2==2.9.9
|
psycopg2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -653,7 +653,10 @@ def api_missing_wikidata_items():
|
||||||
@app.route("/api/1/search")
|
@app.route("/api/1/search")
|
||||||
def api_search():
|
def api_search():
|
||||||
q = flask.request.args["q"]
|
q = flask.request.args["q"]
|
||||||
hits = nominatim.lookup(q)
|
try:
|
||||||
|
hits = nominatim.lookup(q)
|
||||||
|
except nominatim.SearchError as e:
|
||||||
|
return cors_jsonify({"success": False, "error": str(e)}, 503)
|
||||||
for hit in hits:
|
for hit in hits:
|
||||||
hit["name"] = nominatim.get_hit_name(hit)
|
hit["name"] = nominatim.get_hit_name(hit)
|
||||||
hit["label"] = nominatim.get_hit_label(hit)
|
hit["label"] = nominatim.get_hit_label(hit)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue