Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d721c0f

Browse files
authoredApr 11, 2025
Cheap flight search in progress
1 parent 0ab1f2e commit d721c0f

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed
 

‎day-39/data_manager.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import requests
2+
from pprint import pprint
3+
import os
4+
from dotenv import load_dotenv
5+
load_dotenv()
6+
SHEETY_URL = os.getenv('SHEETY_URL')
7+
username = os.getenv("USERNAME")
8+
password = os.getenv("PASSWORD")
9+
USER_AUTH =(f'{username}',f'{password}')
10+
class DataManager:
11+
def __init__(self):
12+
#This class is responsible for talking to the Google Sheet.
13+
#Sheety API keys and url
14+
15+
self.header_json = {
16+
'Content-Type':'application/json'
17+
}
18+
self.data = {
19+
20+
'price': {
21+
'city': 'Rawalpind',
22+
'iataCode': 'LHR',
23+
'lowestPrice': '22'
24+
}
25+
}
26+
27+
def get_destination_data(self):
28+
response_getprice = requests.get(url=SHEETY_URL,headers=self.header_json,auth=USER_AUTH)
29+
self.destination_data = response_getprice.json()['prices']
30+
return self.destination_data
31+
32+
def post(self):
33+
response_sheety = requests.get(url=SHEETY_URL,headers= self.header_json)
34+
print(response_sheety.status_code)
35+
pprint(response_sheety.json())
36+
37+
def put(self):
38+
for i in self.destination_data:
39+
self.putdata = {
40+
'price': {
41+
'iataCode': i['iataCode']
42+
}
43+
}
44+
response_put = requests.put(url=f"{SHEETY_URL}/{i['id']}", headers=self.header_json, json=self.putdata, auth=USER_AUTH)
45+
print(response_put.status_code)
46+
pprint(response_put.json())
47+
print(response_put.text)
48+

‎day-39/flight_data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class FlightData:
2+
#This class is responsible for structuring the flight data.
3+
pass

‎day-39/flight_search.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class FlightSearch:
2+
#This class is responsible for talking to the Flight Search API.
3+
#AMADEUS KEYS
4+
5+
6+
def get_destination_code(self,city_name):
7+
code = "bhwo"
8+
return code
9+

‎day-39/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#This file will need to use the DataManager,FlightSearch, FlightData, NotificationManager classes to achieve the program requirements.
2+
import flight_data
3+
from flight_search import FlightSearch
4+
from data_manager import DataManager
5+
import notification_manager
6+
7+
8+
9+
data_manager = DataManager()
10+
flight_search = FlightSearch()
11+
sheet_data = data_manager.get_destination_data()
12+
13+
14+
15+
16+
if sheet_data[0]['iataCode']=='':
17+
for row in sheet_data:
18+
row['iataCode'] = flight_search.get_destination_code(row['city'])
19+
print(f"sheet_data:\n {sheet_data}")
20+
21+
data_manager.destination_data = sheet_data
22+
data_manager.put()

‎day-39/notification_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class NotificationManager:
2+
#This class is responsible for sending notifications with the deal flight details.
3+
pass

0 commit comments

Comments
 (0)
Please sign in to comment.