-
Notifications
You must be signed in to change notification settings - Fork 0
/
sheety_api.py
42 lines (36 loc) · 1.53 KB
/
sheety_api.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
import requests
from constants import SheetyConst
class SheetyApi(SheetyConst):
"""Manages connection with sheety.co api"""
def __init__(self):
self.response_json = {}
def add_data(self, data: dict, iata_code: str):
"""Adds row in google docs via sheety.co api"""
record = {
"price": {"city": data["city"],
"iataCode": iata_code,
"ticketsMaximumPrice": data["ticketsMaximumPrice"],
}
}
response = requests.post(url=self.SHEETY_ENDPOINT, headers=self.SHEETY_HEADERS, json=record)
response.raise_for_status()
def request_data(self):
"""Requests data from google doc sheet via sheety.co API"""
response = requests.get(url=self.SHEETY_ENDPOINT, headers=self.SHEETY_HEADERS)
response.raise_for_status()
self.response_json = response.json()
def update_data(self, price: str, row_id: int):
"""Updates row in google docs via sheety.co api"""
record = {
"price": {
"ticketsMaximumPrice": price,
}
}
url = self.SHEETY_ENDPOINT + f"/{row_id}"
response = requests.put(url=url, headers=self.SHEETY_HEADERS, json=record)
response.raise_for_status()
def delete_data(self, row_id: int):
"""Deletes row in google docs via sheety.co api"""
url = self.SHEETY_ENDPOINT + f"/{row_id}"
response = requests.delete(url=url, headers=self.SHEETY_HEADERS)
response.raise_for_status()