-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
55 lines (46 loc) · 1.73 KB
/
run.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
import json
import importlib
import sys
from voe.util import process_date_input, process_airport_input
def main():
(date_departure, date_arrival, fixed_departure_month, fixed_arrival_month,
next_clicks_departure, next_clicks_arrival) = process_date_input(None, None)
airport_from, airport_to = process_airport_input(None, None)
module_name = "voe.backend.{}".format(sys.argv[1])
backend_impl = importlib.import_module(module_name)
results = backend_impl.run(airport_from,
airport_to,
date_departure,
date_arrival,
fixed_departure_month,
fixed_arrival_month,
next_clicks_departure,
next_clicks_arrival)
_from = airport_from
_to = airport_to
route_id = "{}-{}".format(_from, _to)
rev_route_id = "{}-{}".format(_to, _from)
routes = {}
for i in range(1, 13):
routes[i] = {}
departures = results[0]
arrivals = results[1]
for dep in departures:
date = dep['date']
dep['departure_date'] = date.strftime('%-d/%m')
dep['departure_price'] = dep['price']
dep['route'] = route_id
del dep['date']
routes[date.month][date.day] = dep
for arr in arrivals:
date = arr['date']
arr['arrival_date'] = date.strftime('%-d/%m')
arr['arrival_price'] = arr['price']
arr['rev_route'] = rev_route_id
del arr['date']
previous = routes[date.month][date.day]
arr.update(previous)
routes[date.month][date.day] = arr
print(json.dumps(routes, indent=4))
if __name__ == "__main__":
main()