-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetro_route.py
119 lines (73 loc) · 2.97 KB
/
metro_route.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import requests
def get_metro_route(source,destination):
route = ''
response = requests.get('https://us-central1-delhimetroapi.cloudfunctions.net/route-get?from={}&to={}'.format(source,destination))
json = response.json()
for metro_station in json['path']:
if metro_station in json['interchange']:
route += metro_station + ' - ' + 'interchange' + '\n'
else:
route += metro_station + '\n'
return route
def get_station_list(letter):
if letter == 'All Stations':
metro_stations = ''
response = requests.get('https://raw.githubusercontent.com/Mansehej/DelhiMetroAPI/master/StationList.txt')
stations = response.text
number = 0
for station in stations.split('\n'):
number += 1
metro_stations += str(number) + '.' + station + '\n'
return metro_stations
else:
metro_stations = ''
response = requests.get('https://raw.githubusercontent.com/Mansehej/DelhiMetroAPI/master/StationList.txt')
stations = response.text
number = 0
for station in stations.split('\n'):
if station.startswith(letter):
number += 1
metro_stations += str(number) + '.' + station + '\n'
else:
continue
return metro_stations
def get_time(source,destination):
response = requests.get('https://us-central1-delhimetroapi.cloudfunctions.net/route-get?from={}&to={}'.format(source,destination))
json = response.json()
time = json['time']
return time
def get_distance(source,destination):
response = requests.get('https://us-central1-delhimetroapi.cloudfunctions.net/route-get?from={}&to={}'.format(source,destination))
json = response.json()
distance = 45 * json['time'] / 60
return distance
def get_fare(source,destination):
fare = get_distance(source,destination) * 2
return fare
want_to_do = input('do you want to get station list or get metro route or get time or get distance or get fare: ')
if want_to_do == 'get time':
source_metro_station = input('Enter onboarding metro station: ')
destination_metro_station = input('Enter destination metro station: ')
time = get_time(source_metro_station,destination_metro_station)
print(time,'minutes')
if want_to_do == 'get metro route':
source_metro_station = input('Enter onboarding metro station: ')
destination_metro_station = input('Enter destination metro station: ')
route = get_metro_route(source_metro_station,destination_metro_station)
print()
print(route)
if want_to_do == 'get station list':
letter = input("type a letter which's stations you want to get or if you want to get all stations kjust type All Stations: ")
metro_stations = get_station_list(letter)
print()
print(metro_stations)
if want_to_do == 'get distance':
source = input('Enter source metro station: ')
destination = input('Enter destination metro station: ')
distance = get_distance(source,destination)
print(distance,'km')
if want_to_do == 'get fare':
source = input('Enter source metro station: ')
destination = input('Enter destination metro station: ')
fare = get_fare(source,destination)
print(fare,'₹')