blob: 7a215953ffd39552b9695aab938726455fe13f79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import overpy
import sys
import simplejson as sjson
import json
import geocoder
g = geocoder.ip('me')
def maxspeed(coordinates, radius):
lat, lon = coordinates
api = overpy.Overpass()
result = api.query("""
way(around:""" + radius + """,""" + lat + """,""" + lon + """) ["maxspeed"];
(._;>;);
out body;
""")
results_list = []
for way in result.ways:
road = {}
road["name"] = way.tags.get("name", "n/a")
road["speed_limit"] = way.tags.get("maxspeed", "n/a")
nodes = []
for node in way.nodes:
nodes.append((node.lat, node.lon))
road["nodes"] = nodes
results_list.append(road)
return results_list
results = maxspeed((sys.argv[1], sys.argv[2]), sys.argv[3])
# Alternative
# results = maxspeed((lat, long, radius))
speedlimit = sjson.dumps(results[0]['speed_limit']).strip('\"')
print(speedlimit)
|