-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsheety_api.py
More file actions
34 lines (32 loc) · 1.21 KB
/
sheety_api.py
File metadata and controls
34 lines (32 loc) · 1.21 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
import requests
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
class SheetyAPI:
def __init__(self):
"""Initialize Sheety API with the base URL from environment variables."""
self.base_url = os.getenv("SHEETY_URL")
if not self.base_url:
raise ValueError("Sheety URL not found. Check your .env file.")
def post_flight(self, flight):
"""Send flight data to Sheety API."""
# Ensure correct key names matching Google Sheet headers
new_data = {
"price": { # ✅ This should match the sheet name in Sheety
"origin": flight['origin'],
"destination": flight['destination'],
"departure": flight['departure_date'],
"return": flight['return_date'],
"price": flight['price']
}
}
# Send data to Sheety
response = requests.post(self.base_url, json=new_data)
# Handle response
if response.status_code == 200:
print("✅ Flight added successfully!")
return response.json()
else:
print(f"❌ Error {response.status_code}: {response.text}")
return None