Format code with black
This commit is contained in:
parent
6e9b2eb50e
commit
5c01d9aebf
|
@ -12,6 +12,7 @@ from .database import session
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
Base.query = session.query_property()
|
Base.query = session.query_property()
|
||||||
|
|
||||||
|
|
||||||
class Polygon(Base):
|
class Polygon(Base):
|
||||||
__tablename__ = "planet_osm_polygon"
|
__tablename__ = "planet_osm_polygon"
|
||||||
|
|
||||||
|
@ -35,10 +36,12 @@ class Polygon(Base):
|
||||||
@classmethod
|
@classmethod
|
||||||
def coords_within(cls, lat, lon):
|
def coords_within(cls, lat, lon):
|
||||||
point = func.ST_SetSRID(func.ST_MakePoint(lon, lat), 4326)
|
point = func.ST_SetSRID(func.ST_MakePoint(lon, lat), 4326)
|
||||||
return (cls.query.filter(cls.admin_level.isnot(None),
|
return cls.query.filter(
|
||||||
|
cls.admin_level.isnot(None),
|
||||||
cls.admin_level.regexp_match("^\d+$"),
|
cls.admin_level.regexp_match("^\d+$"),
|
||||||
func.ST_Within(point, cls.way))
|
func.ST_Within(point, cls.way),
|
||||||
.order_by(cls.area, cast(cls.admin_level, Integer).desc()))
|
).order_by(cls.area, cast(cls.admin_level, Integer).desc())
|
||||||
|
|
||||||
|
|
||||||
class Scotland(Base):
|
class Scotland(Base):
|
||||||
__tablename__ = "scotland"
|
__tablename__ = "scotland"
|
||||||
|
@ -54,4 +57,3 @@ class Scotland(Base):
|
||||||
name = Column(String(50))
|
name = Column(String(50))
|
||||||
|
|
||||||
geom = Column(Geometry("MULTIPOLYGON", srid=27700))
|
geom = Column(Geometry("MULTIPOLYGON", srid=27700))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
|
|
||||||
def get_scotland_code(lat, lon):
|
def get_scotland_code(lat, lon):
|
||||||
conn = psycopg2.connect(**current_app.config["DB_PARAMS"])
|
conn = psycopg2.connect(**current_app.config["DB_PARAMS"])
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
|
@ -65,6 +65,7 @@ def wd_uri_to_qid(value):
|
||||||
assert value.startswith(wd_entity)
|
assert value.startswith(wd_entity)
|
||||||
return value[len(wd_entity) - 1 :]
|
return value[len(wd_entity) - 1 :]
|
||||||
|
|
||||||
|
|
||||||
def geosearch_query(lat, lon):
|
def geosearch_query(lat, lon):
|
||||||
if isinstance(lat, float):
|
if isinstance(lat, float):
|
||||||
lat = f"{lat:f}"
|
lat = f"{lat:f}"
|
||||||
|
|
10
lookup.py
10
lookup.py
|
@ -12,7 +12,7 @@ database.init_app(app)
|
||||||
|
|
||||||
|
|
||||||
def get_random_lat_lon():
|
def get_random_lat_lon():
|
||||||
""" Select random lat/lon within the UK """
|
"""Select random lat/lon within the UK"""
|
||||||
south, east = 50.8520, 0.3536
|
south, east = 50.8520, 0.3536
|
||||||
north, west = 53.7984, -2.7296
|
north, west = 53.7984, -2.7296
|
||||||
|
|
||||||
|
@ -179,13 +179,7 @@ def detail_page():
|
||||||
reply = lat_lon_to_wikidata(lat, lon)
|
reply = lat_lon_to_wikidata(lat, lon)
|
||||||
except wikidata.QueryError as e:
|
except wikidata.QueryError as e:
|
||||||
query, r = e.args
|
query, r = e.args
|
||||||
return render_template(
|
return render_template("query_error.html", lat=lat, lon=lon, query=query, r=r)
|
||||||
"query_error.html",
|
|
||||||
lat=lat,
|
|
||||||
lon=lon,
|
|
||||||
query=query,
|
|
||||||
r=r
|
|
||||||
)
|
|
||||||
|
|
||||||
return render_template("detail.html", lat=lat, lon=lon, **reply)
|
return render_template("detail.html", lat=lat, lon=lon, **reply)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue