Skip to content

Instantly share code, notes, and snippets.

@mmsesay
Created November 9, 2019 18:57
Show Gist options
  • Save mmsesay/714b3bba941b7923df2ef1c76a3ae63b to your computer and use it in GitHub Desktop.
Save mmsesay/714b3bba941b7923df2ef1c76a3ae63b to your computer and use it in GitHub Desktop.
This is the code that i got so far for today
#!/usr/bin/python3
import csv
import json
import time
import requests
currentTime = int(time.time()) #currentTime in second
takeOffTime = currentTime - 3600 * 48 # 48h in the past
# all departure flights
def departures(airport):
url = f'https://opensky-network.org/api/flights/departure?airport={airport}&begin=1517227200&end=1517230800'
response = requests.get(url)
res = response.json() # pass data as json
# print(res) # print the reterived data
dept = ''
arr = ''
# loop through the res
for r in res:
dept = r['estDepartureAirport']
arr = r['estArrivalAirport']
print('Aeparture AirPort: {} - Arrival Airport: {}'.format(dept,arr))
print('--------------------------------------------------')
# read from the csv file
# with open('./airports.csv', mode='r') as csvfile:
# # reading the csv file
# content = csv.reader(csvfile)
# # loop through the csvfile
# for con in content:
# # check if the dept is in csv file
# if con[5] == dept:
# lat = con[6]
# lon = con[7]
# print('lat: {} | lon: {}'.format(lat,lon))
# else:
# print('Not found')
departures("KBDR")
# KBDR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment