-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (44 loc) · 2.13 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
from datetime import datetime, timedelta
from data_manager import DataManager
from flight_search import FlightSearch
from notification_manager import NotificationManager
data_manager = DataManager()
sheet_data = data_manager.get_destination_data()
flight_search = FlightSearch()
notification_manager = NotificationManager()
ORIGIN_CITY_IATA = "LON"
# --- Adding the IataCode in the missing rows by calling Tequila fligh search API --- #
for item in sheet_data:
if item['iataCode'] == "":
for row in sheet_data:
row["iataCode"] = flight_search.get_destination_code(row["city"])
data_manager.destination_data = sheet_data
data_manager.update_destination_codes()
tomorrow = datetime.now() + timedelta(days=1)
six_month_from_today = datetime.now() + timedelta(days=(6 * 30))
# --- Calling flight search API, to find flights and sending the details in SMS and Email by including links --- #
for destination in sheet_data:
flight = flight_search.check_flights(
ORIGIN_CITY_IATA,
destination["iataCode"],
from_time=tomorrow,
to_time=six_month_from_today
)
if flight is None:
continue
if flight.price < destination["lowestPrice"]:
users = data_manager.get_customer_emails()
emails = [row["email"] for row in users]
names = [row["firstName"] for row in users]
text = f"Low price alert! £{flight.price} to fly from {flight.origin_city}-" \
f"{flight.origin_airport} to {flight.destination_city}-{flight.destination_airport}, from " \
f"{flight.out_date} to {flight.return_date}."
notification_manager.send_sms(
message=text
)
if flight.stop_overs > 0:
text += f"\n\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}." \
f"{flight.out_date}*{flight.destination_airport}.{flight.origin_airport}.{flight.return_date}\n\n" \
f"{flight.link}"
notification_manager.send_emails(emails, text, link)