New function to generate random coords
This commit is contained in:
parent
0df666742e
commit
365d81a1f0
21
lookup.py
21
lookup.py
|
@ -15,12 +15,6 @@ from geopy.distance import distance
|
||||||
commons_cat_start = 'https://commons.wikimedia.org/wiki/Category:'
|
commons_cat_start = 'https://commons.wikimedia.org/wiki/Category:'
|
||||||
use_cache = False
|
use_cache = False
|
||||||
|
|
||||||
south = 50.8520
|
|
||||||
east = 0.3536
|
|
||||||
|
|
||||||
north = 53.7984
|
|
||||||
west = -2.7296
|
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': 'UK gecode/0.1 (edward@4angle.com)',
|
'User-Agent': 'UK gecode/0.1 (edward@4angle.com)',
|
||||||
}
|
}
|
||||||
|
@ -77,18 +71,29 @@ class QueryError(Exception):
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.debug = True
|
app.debug = True
|
||||||
|
|
||||||
|
|
||||||
|
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
|
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")
|
@app.route("/random")
|
||||||
def random_location():
|
def random_location():
|
||||||
lat = random.randrange(int(south * mul), int(north * mul)) / mul
|
lat, lon = get_random_lat_lon()
|
||||||
lon = random.randrange(int(west * mul), int(east * mul)) / mul
|
|
||||||
|
|
||||||
elements = get_osm_elements(lat, lon)
|
elements = get_osm_elements(lat, lon)
|
||||||
result = do_lookup(elements, lat, lon)
|
result = do_lookup(elements, lat, lon)
|
||||||
|
|
||||||
return render_template('random.html', lat=lat, lon=lon, result=result, elements=elements)
|
return render_template('random.html', lat=lat, lon=lon, result=result, elements=elements)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/wikidata_tag")
|
@app.route("/wikidata_tag")
|
||||||
def wikidata_tag():
|
def wikidata_tag():
|
||||||
lat = float(request.args.get('lat'))
|
lat = float(request.args.get('lat'))
|
||||||
|
|
Loading…
Reference in a new issue