-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
63 lines (43 loc) · 2.07 KB
/
main.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
from typing import Optional
from moovit_crawler import MoovitCrawler
from utils.message_manager import MessageManager
from location import Location
from route import Route
MAX_NOT_USER_DEPENDABLE_ACTIONS = 1
def choose_location(destination_location: str,
moovit_crawler: MoovitCrawler,
received_location_from: Optional[str]=None) -> Location:
if not received_location_from:
received_location_from = input(f'Enter {destination_location} location: ')
location_from_suggestions = \
moovit_crawler.get_location_suggestions(received_location_from)
p_location_from_suggestions = list(map(lambda l: Location(l),
location_from_suggestions))
if len(p_location_from_suggestions) == 1:
return p_location_from_suggestions[0]
for index, suggested_from_location in enumerate(
p_location_from_suggestions):
print(f'[{index}] {suggested_from_location.location_name}')
selected_index = input('Enter the location number: ')
while (not selected_index.isdigit() or
int(selected_index) not in range(len(p_location_from_suggestions))):
selected_index = input('Wring number! Enter again: ')
return p_location_from_suggestions[int(selected_index)]
if __name__ == '__main__':
moovit_crawler = MoovitCrawler()
origin_location = choose_location('origin', moovit_crawler)
dest_location = choose_location('dest', moovit_crawler)
results = moovit_crawler.search_route(origin_location, dest_location)
routes = [Route(result) for result in results]
clean_routes = []
for route in routes:
if (not route.is_empty_route() and
route.not_user_dependable_counter() <= MAX_NOT_USER_DEPENDABLE_ACTIONS):
clean_routes.append(route)
message_manager = MessageManager()
alerts = [route.get_alert() for route in clean_routes]
for route in clean_routes:
print(route)
print('-'*100)
for alert in alerts:
message_manager.show_message(alert.title, alert.message)