-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_manager.py
More file actions
72 lines (62 loc) · 2.07 KB
/
data_manager.py
File metadata and controls
72 lines (62 loc) · 2.07 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
64
65
66
67
68
69
70
71
72
import os
import requests
from dotenv import load_dotenv
import gspread
from google.oauth2.service_account import Credentials
scopes = [
"https://www.googleapis.com/auth/spreadsheets"
]
creds = Credentials.from_service_account_file("credentials.json", scopes=scopes)
client = gspread.authorize(creds)
# //for sheety api
# sheet_id = "1hZlxWuJXFyVVQa71YzTmUt5HtbjFUEFF9PbP8Ets_Yg"
# sheet = client.open_by_key(sheet_id)
load_dotenv()
SHEETDB_PRICES_ENDPOINT = "https://sheetdb.io/api/v1/7qoxp4nvri10q"
sheetdb_header = {
"Authorization": f"Bearer {os.getenv('SHEETDB_TOKEN')}"
}
class DataManager:
def __init__(self):
self.destination_data = {}
self.customer_data = {}
def get_destination_data(self):
data = {
'sheet': "prices"
}
response = requests.get(
url=SHEETDB_PRICES_ENDPOINT,
json=data,
headers=sheetdb_header)
data = response.json()
# print(data)
self.destination_data = data
return self.destination_data
def update_iata_codes(self):
for city in self.destination_data:
new_data = {
'sheet': "prices",
'data': {
'IATA Code': city["IATA Code"],
}
}
response = requests.patch(
url=f"{SHEETDB_PRICES_ENDPOINT}/City/{city["City"]}",
json=new_data,
headers=sheetdb_header
)
print(f"Response code: {response.status_code}. Body: {response.text}")
def get_customer_emails(self):
data = {
'sheet': "users"
}
response = requests.get(
url=SHEETDB_PRICES_ENDPOINT,
json=data,
headers=sheetdb_header)
self.customer_data = response.json()
# print(self.customer_data)
email_list = []
for customer in self.customer_data:
email_list.append(customer["What is your email?"])
return email_list