generated from hjess/PythonTemplateProject
[main] Prod Creds
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 2m8s
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 2m8s
This commit is contained in:
Binary file not shown.
@@ -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")
|
||||
|
||||
45
inspiration/TingSomSkalTilføjes/flight_types.py
Normal file
45
inspiration/TingSomSkalTilføjes/flight_types.py
Normal 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]
|
||||
1
inspiration/TingSomSkalTilføjes/json_data.json
Normal file
1
inspiration/TingSomSkalTilføjes/json_data.json
Normal file
@@ -0,0 +1 @@
|
||||
[]
|
||||
1
inspiration/rnh_tax_calculator
Submodule
1
inspiration/rnh_tax_calculator
Submodule
Submodule inspiration/rnh_tax_calculator added at 7877b98884
Reference in New Issue
Block a user