-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_manager.py
43 lines (37 loc) · 1.22 KB
/
data_manager.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
from pprint import pprint
import requests
import os
from dotenv import load_dotenv
load_dotenv()
class DataManager:
# This class is responsible for talking to the Google Sheet.
def __init__(self):
self.endpoint = os.getenv("SHEETY_ENDPOINT")
self.data = {}
def get_data(self):
response = requests.get(url=f"{self.endpoint}")
data = response.json()
self.airport_data = data["prices"]
return self.airport_data
def update_iatacodes(self):
for city in self.airport_data:
new_data = {
"price": {
"iataCode": city["iataCode"]
}
}
response = requests.put(
url=f"{self.endpoint}/{city['id']}", json=new_data)
response.raise_for_status()
pprint(response.text)
def update_lowest_price(self, sheet_data):
for city in sheet_data:
new_data = {
"price": {
"lowestPrice": city["lowestPrice"]
}
}
response = requests.put(
url=f"{self.endpoint}/{city['id']}", json=new_data)
response.raise_for_status()
pprint(response.text)