-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapi.py
34 lines (25 loc) · 787 Bytes
/
webapi.py
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
__author__ = 'yk'
import requests
import json
import handicap
BASE = "http://130.211.166.43:8008/web/api.php/v1"
def get_route(params):
url = BASE + "/connections"
print ("Trying: " ,url)
resp = requests.get(url, params=params)
jsn = resp.json()
if 'connections' not in jsn:
return []
cns = jsn['connections']
handicap.annotate_connections(cns)
return cns
def search_name(query):
url = BASE + "/locations"
resp = requests.get(url, params={'query': query})
jsn = resp.json()
if 'stations' not in jsn:
return []
return list(map(lambda x: x['name'], jsn['stations']))
if __name__ == '__main__':
print(list(search_name("Zuri")))
print(json.dumps(get_route({"from":"Lausanne","to":"Bern"})[0],indent=True))