-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (41 loc) · 1.97 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
from datetime import datetime, timedelta
from data_manager import DataManager
from flight_search import FlightSearch
from notification_manager import NotificationManager
ORIGIN_CITY_IATA = "LON"
data_manager = DataManager()
flight_search = FlightSearch()
notification_manager = NotificationManager()
sheet_data = data_manager.get_destination_data()
if sheet_data[0]["iataCode"] == "":
city_names = [row["city"] for row in sheet_data]
data_manager.city_codes = flight_search.get_destination_codes(city_names)
data_manager.update_destination_codes()
sheet_data = data_manager.get_destination_data()
destinations = {
data["iataCode"]: {
"id": data["id"],
"city": data["city"],
"price": data["lowestPrice"]
} for data in sheet_data}
tomorrow = datetime.now() + timedelta(days=1)
six_month_from_today = datetime.now() + timedelta(days=6 * 30)
for destination_code in destinations:
flight = flight_search.check_flights(
ORIGIN_CITY_IATA,
destination_code,
from_time=tomorrow,
to_time=six_month_from_today
)
print(flight.price)
if flight is None:
continue
if flight.price < destinations[destination_code]["price"]:
users = data_manager.get_customer_emails()
emails = [row["email"] for row in users]
names = [row["firstName"] for row in users]
message = f"Low price alert! Only £{flight.price} to fly from {flight.origin_city}-{flight.origin_airport} to {flight.destination_city}-{flight.destination_airport}, from {flight.out_date} to {flight.return_date}."
if flight.stop_overs > 0:
message += f"\nFlight has {flight.stop_overs} stop over, via {flight.via_city}."
link = f"https://www.google.co.uk/flights?hl=en#flt={flight.origin_airport}.{flight.destination_airport}.{flight.out_date}*{flight.destination_airport}.{flight.origin_airport}.{flight.return_date}"
notification_manager.send_emails(emails, message, link)