From 365d81a1f08e9f3fe1670b98ed8c8ab03f7d1f1a Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 16 Apr 2021 16:14:12 +0100 Subject: [PATCH] New function to generate random coords --- lookup.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lookup.py b/lookup.py index 1e98913..d6e6f0a 100755 --- a/lookup.py +++ b/lookup.py @@ -15,12 +15,6 @@ from geopy.distance import distance commons_cat_start = 'https://commons.wikimedia.org/wiki/Category:' use_cache = False -south = 50.8520 -east = 0.3536 - -north = 53.7984 -west = -2.7296 - headers = { 'User-Agent': 'UK gecode/0.1 (edward@4angle.com)', } @@ -77,18 +71,29 @@ class QueryError(Exception): app = Flask(__name__) app.debug = True -mul = 10000 + +def get_random_lat_lon(): + ''' Select random lat/lon within the UK ''' + south, east = 50.8520, 0.3536 + north, west = 53.7984, -2.7296 + + mul = 10000 + lat = random.randrange(int(south * mul), int(north * mul)) / mul + lon = random.randrange(int(west * mul), int(east * mul)) / mul + + return lat, lon + @app.route("/random") def random_location(): - lat = random.randrange(int(south * mul), int(north * mul)) / mul - lon = random.randrange(int(west * mul), int(east * mul)) / mul + lat, lon = get_random_lat_lon() elements = get_osm_elements(lat, lon) result = do_lookup(elements, lat, lon) return render_template('random.html', lat=lat, lon=lon, result=result, elements=elements) + @app.route("/wikidata_tag") def wikidata_tag(): lat = float(request.args.get('lat'))