Basic ADSBX single icao vs entire globe json conf
This commit is contained in:
parent
fa3c637d07
commit
99122d48c2
|
|
@ -0,0 +1,18 @@
|
||||||
|
[DATA]
|
||||||
|
#Source to pull data from
|
||||||
|
#SHOULD BE ADSBX which is ADS-B Exchange or OPENS which is OpenSky
|
||||||
|
#By default configured with OpenSky which anyone can use without a login
|
||||||
|
#ADS-B Exchange has better data but is not avalible unless you feed their network or pay.
|
||||||
|
SOURCE = OPENS
|
||||||
|
|
||||||
|
|
||||||
|
#ADS-B Exchange https://www.adsbexchange.com/data/
|
||||||
|
[ADSBX]
|
||||||
|
API_KEY = apikey
|
||||||
|
|
||||||
|
#OpenSky https://opensky-network.org/apidoc/index.html
|
||||||
|
#When using without your own login user and pass should be None
|
||||||
|
[OPENSKY]
|
||||||
|
USERNAME = None
|
||||||
|
PASSWORD = None
|
||||||
|
|
||||||
|
|
@ -2,27 +2,42 @@ import requests
|
||||||
import configparser
|
import configparser
|
||||||
import json
|
import json
|
||||||
main_config = configparser.ConfigParser()
|
main_config = configparser.ConfigParser()
|
||||||
main_config.read('config.ini')
|
main_config.read('mainconf.ini')
|
||||||
url = "https://adsbexchange.com/api/aircraft/json/"
|
import os
|
||||||
headers = {
|
#Set ADSBX URL Based off amount of Conf files
|
||||||
|
if main_config.get('DATA', 'SOURCE') == "ADSBX":
|
||||||
|
for filename in os.listdir(os. getcwd()):
|
||||||
|
if filename.endswith(".ini") and filename != "mainconf.ini":
|
||||||
|
plane_config = configparser.ConfigParser()
|
||||||
|
plane_config.read(filename)
|
||||||
|
plane_config.get('DATA', 'ICAO')
|
||||||
|
icao_list = []
|
||||||
|
icao_list.append(plane_config.get('DATA', 'ICAO'))
|
||||||
|
if len(icao_list) > 1:
|
||||||
|
url = "https://adsbexchange.com/api/aircraft/json/"
|
||||||
|
elif len(icao_list) == 1:
|
||||||
|
url = "https://adsbexchange.com/api/aircraft/icao/" + icao_list[0].upper() + "/"
|
||||||
|
|
||||||
|
headers = {
|
||||||
'api-auth': main_config.get('ADSBX', 'API_KEY'),
|
'api-auth': main_config.get('ADSBX', 'API_KEY'),
|
||||||
'Content-Encoding': 'gzip'
|
'Content-Encoding': 'gzip'
|
||||||
}
|
}
|
||||||
|
if main_config.get('DATA', 'SOURCE') == "OPENS":
|
||||||
|
|
||||||
response = requests.get(url, headers = headers)
|
while True:
|
||||||
data = response.text
|
if main_config.get('DATA', 'SOURCE') == "ADSBX":
|
||||||
data = json.loads(data)
|
response = requests.get(url, headers = headers)
|
||||||
|
data = response.text
|
||||||
#Test Parse
|
data = json.loads(data)
|
||||||
for plane in data['ac']:
|
for plane in data['ac']:
|
||||||
if plane['icao'] == "4074B8":
|
if plane['icao'] == "4074B8":
|
||||||
print(plane)
|
print(plane)
|
||||||
#print(json.dumps(data, indent=2))
|
#print(json.dumps(data, indent=2))
|
||||||
print("done")
|
print("done")
|
||||||
#Initate Each Plane Object from their configs
|
#Initate Each Plane Object from their configs
|
||||||
import os
|
|
||||||
for filename in os.listdir(os. getcwd()):
|
|
||||||
if filename.endswith(".ini") and filename != "mainconf.ini":
|
|
||||||
plane_config = configparser.ConfigParser()
|
plane_config = configparser.ConfigParser()
|
||||||
plane_config.read(filename)
|
plane_config.read(filename)
|
||||||
print(filename)
|
print(filename)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue