forked from xmsley614/nt_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuse_ac.py
53 lines (52 loc) · 1.8 KB
/
use_ac.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
import time
from datetime import datetime, timedelta
from nt_models import PriceFilter, CabinClass, AirBoundFilter
from nt_parser import convert_ac_response_to_models, results_to_excel
from nt_filter import filter_prices, filter_airbounds
from ac_searcher import Ac_Searcher
from utils import date_range
if __name__ == '__main__':
origins = ['LAX']
destinations = ['TYO']
start_dt = '2024-02-01'
end_dt = '2024-02-01'
dates = date_range(start_dt, end_dt)
# means eco, pre, biz and first
cabin_class = [
"ECO",
"PRE",
"BIZ",
"FIRST"
]
airbound_filter = AirBoundFilter(
max_stops=1,
airline_include=[],
airline_exclude=['ET'],
)
price_filter = PriceFilter(
min_quota=1,
max_miles_per_person=999999,
preferred_classes=[CabinClass.J, CabinClass.F, CabinClass.Y],
mixed_cabin_accepted=True
)
# seg_sorter = {
# 'key': 'departure_time', # only takes 'duration_in_all', 'stops', 'departure_time' and 'arrival_time'.
# 'ascending': True
# }
acs = Ac_Searcher()
airbounds = []
for ori in origins:
for des in destinations:
for date in dates:
print(f'search for {ori} to {des} on {date} @ {datetime.now().strftime("%H:%M:%S")}')
response = acs.search_for(ori, des, date, cabin_class)
v1 = convert_ac_response_to_models(response)
airbounds.extend(v1)
# if there are high volume of network requests, add time.sleep
# time.sleep(1)
airbounds = filter_airbounds(airbounds, airbound_filter)
airbounds = filter_prices(airbounds, price_filter)
results = []
for x in airbounds:
results.extend(x.to_flatted_list())
results_to_excel(results)