Skip to content

Commit bd8c0d8

Browse files
authored
Create data_manager.py
1 parent 65a5916 commit bd8c0d8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

day40/data_manager.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import requests
2+
3+
SHEETY_PRICES_ENDPOINT = "https://api.sheety.co/********************************/flightDeals/prices/"
4+
SHEETY_USERS_ENDPOINT = "https://api.sheety.co/*********************************/flightDeals/users"
5+
6+
7+
class DataManager:
8+
9+
def __init__(self):
10+
self.destination_data = {}
11+
12+
def get_destination_data(self):
13+
response = requests.get(url=SHEETY_PRICES_ENDPOINT)
14+
data = response.json()
15+
self.destination_data = data["prices"]
16+
return self.destination_data
17+
18+
def update_destination_codes(self):
19+
for city in self.destination_data:
20+
new_data = {
21+
"price": {
22+
"iataCode": city["iataCode"]
23+
}
24+
}
25+
response = requests.put(
26+
url=f"{SHEETY_PRICES_ENDPOINT}/{city['id']}",
27+
json=new_data
28+
)
29+
print(response.text)
30+
31+
def get_customer_emails(self):
32+
customers_endpoint = SHEETY_USERS_ENDPOINT
33+
response = requests.get(url=customers_endpoint)
34+
data = response.json()
35+
self.customer_data = data["users"]
36+
return self.customer_data

0 commit comments

Comments
 (0)