/
runner.py
66 lines (55 loc) · 2.56 KB
/
runner.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
"""
Gets Live API results, records them into MongoDB, records into file and finds min price.
"""
import os
from config import *
from logger import create_logger
from get_api_results_for_n_days import get_api_results_for_n_days
from mongodb_methods import connect_to_mongodb, find_flights_under_threshold_price
from service_methods import files_cleaner
def main():
# create logger
cwd = os.getcwd()
log_file_folder_path = os.path.join(cwd, log_files_folder)
logger = create_logger(log_file_folder_path=log_file_folder_path,
log_file_name=log_file)
# connect to db
collection = connect_to_mongodb(mongodb_instance=instance,
mongodb=db,
mongodb_collection=db_collection,
logger=logger)
# get LIVE API results, record values to db
get_api_results_for_n_days(days=days_to_request,
pickle_file=pickle_file,
base_url=base_url,
headers=headers,
cabin_class=cabin_class,
country=country,
currency=currency,
locale_lang=locale_lang,
city_from=city_from,
city_to=city_to,
country_from=country_from,
country_to=country_to,
outbound_date=outbound_date,
adults_count=adults_count,
max_retries=max_retries,
json_files_folder=json_files_folder,
json_file=json_file,
collection=collection,
logger=logger,
save_to_file=save_to_file,
live_api_mode=live_api_mode)
# find flights with price < threshold
find_flights_under_threshold_price(threshold=price_threshold,
search_date=outbound_date,
collection=collection,
logger=logger)
# clean up log files
log_path_to_clean = os.path.join(cwd, log_files_folder)
files_cleaner(path_to_clean=log_path_to_clean,
extension='log',
to_keep_number=log_files_to_keep,
logger=logger)
if __name__ == "__main__":
main()