diff --git a/datapull.py b/datapull.py index 47eab80..276093d 100644 --- a/datapull.py +++ b/datapull.py @@ -4,17 +4,30 @@ Little script written by Arnold Dechamps import config import requests -apiUrl = "https://aeroapi.flightaware.com/aeroapi/" -airport = config.AIRPORT -payload = {'max_pages': 2} -auth_header = {'x-apikey': config.FLIGHTAWAREKEY} +def main(): + """ + Main function to pull data from flightaware API. Mostly flightaware code with overhead. Will modify if needed + :return: raw data + """ + departures = [] + apiUrl = "https://aeroapi.flightaware.com/aeroapi/" + airport = config.AIRPORT + payload = {'max_pages': 2} + auth_header = {'x-apikey': config.FLIGHTAWAREKEY} -response = requests.get(apiUrl + f"airports/{airport}/flights/scheduled_departures", params=payload, - headers=auth_header) -print("Flight Operator Time Destination acft-type") -if response.status_code == 200: - departures = response.json()["scheduled_departures"] + response = requests.get(apiUrl + f"airports/{airport}/flights/scheduled_departures", params=payload, + headers=auth_header) + print("Flight Operator Time Destination acft-type") + if response.status_code == 200: + departures = response.json()["scheduled_departures"] + else: + print("Error executing request") + return departures + + +if __name__ == '__main__': + departures = main() name = "unknown" operator = "unknown" scheduled_off = "unknown" @@ -34,5 +47,3 @@ if response.status_code == 200: acfttype = flight["aircraft_type"] print(name + " " + operator + " " + scheduled_off + " " + destination + " " + acfttype) -else: - print("Error executing request")