Skip to content

Instantly share code, notes, and snippets.

@anielsen001
Created November 24, 2019 16:44
Show Gist options
  • Save anielsen001/a98892b0f93be5239bf18eafa4ab490a to your computer and use it in GitHub Desktop.
Save anielsen001/a98892b0f93be5239bf18eafa4ab490a to your computer and use it in GitHub Desktop.
adsbexchange.com api interaction
[adsbx]
api_key =
[search]
lat =
lon =
dist =
period = 10
count = 2
#!/usr/bin/env python3
import json
import requests
import datetime
import time
import cronus.beat as beat
import configparser
def get_and_save_adsbx(filename, URL, API_KEY):
headers = { 'api-auth':API_KEY }
res = requests.get( URL, headers = headers )
with open( filename, 'w' ) as f:
json.dump( res.json(), f )
return res
def filename_timestamp( base ):
""" create a filename with a prepended timestamp """
timestr = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
return timestr + '_' + base
if __name__=='__main__':
config = configparser.ConfigParser()
conf_file = 'adsbx.conf'
config.read( conf_file )
adsbxconfig = config['adsbx']
API_KEY = adsbxconfig['api_key']
searchconfig = config['search']
lat = searchconfig['lat']
lon = searchconfig['lon']
dist = searchconfig['dist']
period = float( searchconfig['period'] )
maxcount = int( searchconfig['count'] )
URL = 'https://adsbexchange.com/api/aircraft/json' +\
'/lat/' + lat +\
'/lon/' + lon +\
'/dist/' + dist + '/'
count = 0
beat.set_rate( 1/period ) # rate set in Hz
while beat.true() and count < maxcount:
fname = filename_timestamp( 'absbx.json' )
print( fname )
get_and_save_adsbx( fname, URL, API_KEY )
count += 1
beat.sleep()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment