-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (56 loc) · 2.37 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
64
65
66
67
68
69
70
#This file will need to use the DataManager,FlightSearch, FlightData,
#NotificationManager classes to achieve the program requirements.
from data_manager import DataManager
from flight_search import FlightSearch
from flight_data import FlightData
from notification_manager import NotificationManager
FROM = "LON"
data = DataManager()
flight_search = FlightSearch()
sheet = data.define_data()
# print(sheet)
# Filling blank spaces with IATA codes in sheets
if sheet[0]["iataCode"] == "":
for city in sheet:
city["iataCode"] = flight_search.get_code(city["city"])
data.get_data = sheet
data.update_data()
# Fare
notification = NotificationManager()
for destination in sheet:
flight = flight_search.get_flight_details(
origin_city=FROM,
city_code=destination['iataCode']
)
if flight is None:
continue
if flight.price < destination['lowestPrice']:
users = data.get_customer_emails()
emails = [row["email"] for row in users]
message = f"Subject: New Low Price Alert! \n\nLow price alert! "\
f"Only £{flight.price} to fly from {flight.origin_city}-{flight.origin_airport} to "\
f"{flight.destination_city}-{flight.destination_airport}, "\
f"from {flight.out_date} to {flight.return_date}.\nhttps://www.google.co.uk/flights?hl=en#flt=" \
f"{flight.origin_airport}.{flight.destination_airport}.{flight.out_date}*{flight.destination_airport}" \
f".{flight.origin_airport}.{flight.return_date}"
if flight.stop_over > 0:
message += f"\nFlight has {flight.stop_over} stop over, via {flight.via_city}."
# print(message)
notification.send_msg(message)
notification.send_email(emails, message)
# flight = flight_search.get_flight_details(
# origin_city=FROM,
# city_code=sheet[-1]['iataCode']
# )
# if flight is None:
# continue
#
# if flight.price < sheet[-1]['lowestPrice']:
# message = f"Low price alert! "\
# f"Only £{flight.price} to fly from {flight.origin_city}-{flight.origin_airport} to "\
# f"{flight.destination_city}-{flight.destination_airport}, "\
# f"from {flight.out_date} to {flight.return_date}."
# if flight.stop_over > 0:
# message += f"\nFlight has {flight.stop_overs} stop over, via {flight.via_city}."
#
# print(message)