-
Notifications
You must be signed in to change notification settings - Fork 0
/
ratp_wrapper.py
69 lines (57 loc) · 1.9 KB
/
ratp_wrapper.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import requests
ENDPOINT = 'https://api-ratp.pierre-grimaud.fr/v3'
def format_station_name(station):
if station != None :
station.replace(' ','+')
return station
def build_schedule_request( code, station, type='metros', way='A'):
url = '{0}/{1}/{2}/{3}/{4}/{5}'.format(ENDPOINT, 'schedules', type, code, format_station_name(station), way)
return url
def get_schedule(code, station, type='metros', way='A'):
"""
Get real time information about next time metro
"""
endpoint = build_schedule_request(code, station, type, way)
return requests.get(endpoint)
def build_traffic_request(type=None):
url = '{}/{}'.format(ENDPOINT, 'traffic')
if type != None:
url = '{}/{}'.format(url, type)
return url
def get_traffic(type=None):
"""
Get traffic information about all metros/rer/bus lines
"""
endpoint = build_traffic_request(type)
return requests.get(endpoint)
def build_stations_request(type, code):
url = '{}/{}/{}/{}'.format(ENDPOINT, 'stations', type, code)
return url
def get_stations(type,code):
"""
Get all the stations of a line
"""
endpoint = build_stations_request(type, code)
return requests.get(endpoint)
def build_destinations_request(type, code):
url = '{}/{}/{}/{}'.format(ENDPOINT, 'destinations', type, code)
return url
def get_destinations(type, code):
"""
Get both terminus names.
"""
endpoint = build_destinations_request(type, code)
return requests.get(endpoint)
def build_lines_request(type=None, code=None):
url = '{}/{}'.format(ENDPOINT,'lines')
if type != None:
url = '{}/{}'.format(url, type)
if code != None:
url = '{}/{}'.format(url, code)
return url
def get_lines(type=None, code=None):
"""
Get all lines of transport
"""
endpoint = build_lines_request(type, code)
return requests.get(endpoint)