generated from hjess/PythonTemplateProject
[main] Prod Creds
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 1m10s
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 1m10s
This commit is contained in:
@@ -96,7 +96,7 @@ class AmadeusClient:
|
||||
"""
|
||||
Get a summary of the flight details for a specific date, origin, and destination.
|
||||
|
||||
:param departure_date: The date of travel in YYYY-MM-DD format.
|
||||
:param departure_date: The date oxxf travel in YYYY-MM-DD format.
|
||||
:param origin: The IATA code for the origin location.
|
||||
:param destination: The IATA code for the destination location.
|
||||
:return: Formatted flight summary string.
|
||||
@@ -117,45 +117,32 @@ class AmadeusClient:
|
||||
last_arrival = parsed_flights[-1]["arrival"]["iataCode"]
|
||||
|
||||
#return f"{departure_date}: {first_departure} -> {last_arrival} - {average_price:.2f}"
|
||||
return {"departure_date":departure_date, "departure": first_departure, "arrival": last_arrival,"price": average_price}
|
||||
return {"departure_date":departure_date, "departure": first_departure, "arrival": last_arrival,"price": average_price,"note":"Success"}
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
cd = CalenderMaker()
|
||||
travel_days = cd.get_dates(year = 2025, dest_day="Thursday", orgin_day="Tuesday")
|
||||
travel_days = cd.get_dates(year = 2025, dest_day="Friday", orgin_day="Wednesday")
|
||||
amadeus_client = AmadeusClient( prod = True)
|
||||
import csv
|
||||
|
||||
with open( "summery.txt", 'w' ) as fp, open( 'data_csv.csv', "w" ) as fp2:
|
||||
writer = csv.DictWriter( fp2, fieldnames = ['orgin', 'dest', 'date', 'price','note'] )
|
||||
writer = csv.DictWriter( fp2, fieldnames = ['departure_date', 'departure', 'arrival', 'price','note'] )
|
||||
writer.writeheader()
|
||||
for days in travel_days:
|
||||
origin = days['orgin']
|
||||
destination = days['dest']
|
||||
departure_date = days['date']
|
||||
try:
|
||||
try:
|
||||
summary = amadeus_client.get_flight_summary( departure_date, origin, destination )
|
||||
|
||||
#summary = amadeus_client.get_flight_summary( days['date'], days['departure'], days['arrival'] )
|
||||
summary = amadeus_client.get_flight_summary( days['date'], days['departure'], days['arrival'] )
|
||||
print(summary)
|
||||
writer.writerow( {
|
||||
"orgin": summary["departure_date"],
|
||||
"dest": summary["departure"],
|
||||
"date": summary["arrival"],
|
||||
"price": summary['price'],
|
||||
"note": ""
|
||||
} )
|
||||
writer.writerow({ "departure_date":summary['departure_date'], "departure":summary['departure'], "arrival":summary['arrival'], "price":summary['price'], "note":summary['note'] } )
|
||||
fp.writelines( str(summary) + '\n' )
|
||||
except Exception as e:
|
||||
print( f"Error fetching flight summary for {origin} -> {destination} on {departure_date}" )
|
||||
writer.writerow( {
|
||||
"orgin": origin,
|
||||
"dest": destination,
|
||||
"date": departure_date,
|
||||
"price": 214.0,
|
||||
"note": "False - Flight not found"
|
||||
} )
|
||||
pass
|
||||
#raise e
|
||||
#print( f"Error fetching flight summary for {origin} -> {destination} on {departure_date}" )
|
||||
writer.writerow({ "departure_date":days['date'], "departure":days['departure'], "arrival":days['arrival'], "price":250, "note":"Not fetched - Failed" } )
|
||||
|
||||
except ResponseError as error:
|
||||
print( f"An error occurred: {error}" )
|
||||
|
||||
@@ -166,8 +153,8 @@ if __name__ == "__main__":
|
||||
df.to_excel( writer, sheet_name = 'Sheet1', index = False )
|
||||
|
||||
# Calculate the average monthly data
|
||||
df['date'] = pd.to_datetime( df['date'] )
|
||||
df['month'] = df['date'].dt.to_period( 'M' )
|
||||
df['departure_date'] = pd.to_datetime( df['departure_date'] )
|
||||
df['month'] = df['departure_date'].dt.to_period( 'M' )
|
||||
avg_monthly_data = df.groupby( 'month' )['price'].mean().reset_index()
|
||||
avg_monthly_data.columns = ['Month', 'Average Price']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user