-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (47 loc) · 2.54 KB
/
Copy pathmain.py
File metadata and controls
63 lines (47 loc) · 2.54 KB
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
from data_manager import DataManager
from flight_search import FlightSearch
from notification_manager import NotificationManager
import requests_cache
requests_cache.install_cache(
"flight_cache",
expire_after=3600,
urls_expire_after={
"api.sheety.co": requests_cache.DO_NOT_CACHE,
}
)
if __name__ == "__main__":
data_manager = DataManager()
flight_search = FlightSearch()
notification_manager = NotificationManager()
for destination in data_manager.get_data()["prices"]:
city = destination["city"]
iata_code = destination["airports"]
lowest_price = destination["cheapestFlight"]
row_id = destination["id"]
print(f"Searching flights to {city} ({iata_code})...")
cheapest = flight_search.find_cheapest(iata_code)
if cheapest.price == "N/A":
print(f" No flights found to {city}.")
continue
else:
print(
f" Cheapest: €{cheapest.price} | {cheapest.origin_airport} → "
f"{cheapest.destination_airport} | Out: {cheapest.out_date} | Return: {cheapest.return_date} | With: {cheapest.stops} stop(s)."
)
if cheapest.price < lowest_price:
print(f" Lower price found! (€{cheapest.price} vs sheet €{lowest_price})")
data_manager.update_lowest_price(row_id, cheapest.price, cheapest.out_date, cheapest.return_date, cheapest.stops)
notification_manager.send_sms(city, cheapest)
customer_emails = data_manager.get_customer_emails()["users"]
notification_manager.send_emails(customer_emails, city, cheapest)
"""
Final Day 40 Req:
You should make changes to your data_manager.py, your main.py and your .env file.
* Add your endpoints for your "prices" and your "users" sheets to your .env file.
* Add a method called get_customer_emails() to your data_manager.py. This should return the data on your "users" spreadsheet.
* Update the __init()__ method so that you retrieve all the environment variables in one place. This should include things like your SHEETY_USERNAME , your password, but also your endpoints.
1. Update your .env file with your SMTP address, your email, and your app password.
2. In the notification_manager.py, update your __init__() method so that you retrieve all the environment variables in one place.
3. Create a method in the NotificationManager called send_emails() .
NOTE: when sending emails, it won't like the "£" symbol, you might get an error like the one below:
"""