[main] Prod Creds
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 2m8s

This commit is contained in:
Henrik Jess
2025-01-14 17:25:45 +01:00
parent 0129164fd5
commit 5de92fa7a1
17 changed files with 105 additions and 15 deletions

View File

@@ -1,13 +1,13 @@
import json
from pprint import pprint
from amadeus import Client, ResponseError
import pandas as pd
from datetime import datetime, timedelta
import json
from flight_types import *
class FlightFilter:
def __init__(self, api_key, api_secret):
self.amadeus = Client(client_id=api_key, client_secret=api_secret)
self.amadeus = Client(client_id=api_key, client_secret=api_secret, hostname="production")
def get_flight_offers(self, request_body):
"""
@@ -119,8 +119,12 @@ class FlightFilter:
# Usage example
if __name__ == "__main__":
api_key = "uxDqIh36xPAUvpXnXynwAnH86pGBdIch"
api_secret = "xTSLooNZpJWantb5"
#api_key = "uxDqIh36xPAUvpXnXynwAnH86pGBdIch"
#api_secret = "xTSLooNZpJWantb5"
# PROD PROD PROD PROD PROD PROD PROD PROD PROD PROD
api_key = "ABRGQv6U7IWAYxwwmjqAOPUDGvuFMSjw"
api_secret = "BcwpSKf3FICJIxaw"
flight_filter = FlightFilter(api_key, api_secret)
@@ -153,25 +157,57 @@ if __name__ == "__main__":
"sources": ["GDS"],
"searchCriteria": {
"excludeAllotments": True,
"addOneWayOffers": False,
"maxFlightOffers": 10,
"addOneWayOffers": True,
"maxFlightOffers": 50,
"allowAlternativeFareOptions": True,
}
}
# Fetch flights
flights = flight_filter.get_flight_offers(request_body)
print(f"Raw flights data: {flights}")
with open("json_data.json", "w") as file:
json.dump(flights, file)
#
#DEBUG
#with open("json_data.json", "r") as file:
# flights = json.load(file)
#print(f"Raw flights data: {flights}")
real_flights = []
for flight in flights:
for x,v in flight.items():
if type(v) == list and "itineraries" in str(x).lower():
for flt, flt2 in flight.items():
if flt == "itineraries":
for itm in flt2:
for seg in itm.get("segments"):
departure = seg.get("departure").get("iataCode")
arrival = seg.get("arrival").get("iataCode")
print(f"{departure} -> {arrival}")
if (departure, arrival) in (("OPO", "CPH"), ("CPH", "OPO")):
print( f"{departure} -> {arrival}" )
# Filter flights from OPO to CPH around 07:00 ± 1 hour
opo_to_cph_flights = flight_filter.filter_flights_by_time(
flights, origin_filter="OPO", destination_filter="CPH", filter_time_str="06:00", hours=2
)
#opo_to_cph_flights = flight_filter.filter_flights_by_time(
# flights, origin_filter="OPO", destination_filter="CPH", filter_time_str="06:00", hours=2
#)
# Filter flights from CPH to OPO around 18:30 ± 1 hour
cph_to_opo_flights = flight_filter.filter_flights_by_time(
flights, origin_filter="CPH", destination_filter="OPO", filter_time_str="20:30", hours=2
)
#cph_to_opo_flights = flight_filter.filter_flights_by_time(
# flights, origin_filter="CPH", destination_filter="OPO", filter_time_str="20:30", hours=2
#)
# Save to Excel
flight_filter.save_to_excel(opo_to_cph_flights, cph_to_opo_flights, "Filtered_Flights_OPO_CPH.xlsx")
#flight_filter.save_to_excel(opo_to_cph_flights, cph_to_opo_flights, "Filtered_Flights_OPO_CPH.xlsx")

View File

@@ -0,0 +1,45 @@
from dataclasses import dataclass
from typing import List, Optional
# OopCompanion:suppressRename
@dataclass
class AmenityProvider:
name: str
@dataclass
class Amenity:
description: str
isChargeable: bool
amenityType: str
amenityProvider: AmenityProvider
@dataclass
class IncludedCheckedBags:
quantity: int
@dataclass
class FareDetailsBySegment:
segmentId: str
cabin: str
fareBasis: str
brandedFare: str
brandedFareLabel: str
class_: str # 'class' is a reserved keyword in Python; use 'class_' instead
includedCheckedBags: IncludedCheckedBags
amenities: List[Amenity]
@dataclass
class Price:
currency: str
total: str
base: str
@dataclass
class Traveler:
travelerId: str
fareOption: str
travelerType: str
price: Price
fareDetailsBySegment: List[FareDetailsBySegment]

View File

@@ -0,0 +1 @@
[]