Merge pull request #85 from makrsmark/rapidadsbx-fixes
simplifying rapidadsbx logic
This commit is contained in:
commit
d125ab8d6a
43
__main__.py
43
__main__.py
|
|
@ -190,36 +190,21 @@ try:
|
|||
print(key, "has", len(sorted_ras[key]), "RAs")
|
||||
obj.check_new_ras(sorted_ras[key])
|
||||
obj.expire_ra_types()
|
||||
icao_key = 'hex'
|
||||
from defRpdADSBX import pull_rpdadsbx
|
||||
# print("Planes list: \n"+str((list(planes.keys()))))
|
||||
# print("\nLen planes:\n"+str(len(planes)))
|
||||
p = 0
|
||||
data = dict.fromkeys(['ac'])
|
||||
# print(data)
|
||||
while p < len(planes):
|
||||
planeInfo = pull_rpdadsbx(str(list(planes.keys())[p]))
|
||||
if p == 0:
|
||||
data['ac'] = (planeInfo)['ac']
|
||||
data_indexed = {}
|
||||
for icao in planes:
|
||||
plane = planes[icao]
|
||||
plane_info = pull_rpdadsbx(icao)
|
||||
if plane_info:
|
||||
if plane_info['ac']:
|
||||
data_indexed[icao.upper()] = plane_info['ac'][0]
|
||||
plane.run_adsbx_v2(data_indexed[icao.upper()])
|
||||
else:
|
||||
plane.run_empty()
|
||||
else:
|
||||
data['ac'].extend((planeInfo)['ac'])
|
||||
# print("p = "+str(p))
|
||||
# print(str(list(planes.keys())[p]) + ": " + str(data))
|
||||
p += 1
|
||||
if data is not None:
|
||||
if data['ac'] is not None:
|
||||
data_indexed = {}
|
||||
for planeData in data['ac']:
|
||||
data_indexed[planeData[icao_key].upper()] = planeData
|
||||
for key, obj in planes.items():
|
||||
try:
|
||||
obj.run_adsbx_v2(data_indexed[key.upper()])
|
||||
except KeyError:
|
||||
obj.run_empty()
|
||||
else:
|
||||
for obj in planes.values():
|
||||
obj.run_empty()
|
||||
else:
|
||||
print(f"No data for icao {icao}. Skipping...")
|
||||
plane.run_empty()
|
||||
if not data_indexed:
|
||||
failed_count += 1
|
||||
elif source == "OPENS":
|
||||
from defOpenSky import pull_opensky
|
||||
|
|
@ -286,4 +271,4 @@ except Exception as e:
|
|||
logging.error(str(traceback.format_exc()))
|
||||
from defDiscord import sendDis
|
||||
sendDis(str("Error Exiting: " + str(e) + f"Failed on ({obj.config_path}) https://globe.adsbexchange.com/?icao={key} "), main_config, main_config.get('DISCORD', 'ROLE_ID'), "crash_latest.log")
|
||||
raise e
|
||||
raise e
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import requests
|
||||
import json
|
||||
import configparser
|
||||
from datetime import datetime
|
||||
|
||||
|
|
@ -18,29 +17,18 @@ def pull_rpdadsbx(planes):
|
|||
}
|
||||
try:
|
||||
response = requests.get(url, headers = headers, timeout=30)
|
||||
except Exception as error:
|
||||
print('err.args:' + str(error.args))
|
||||
response = None
|
||||
if response is not None:
|
||||
try:
|
||||
data = json.loads(response.text)
|
||||
except (json.decoder.JSONDecodeError, ValueError) as error_message:
|
||||
print("Error with JSON")
|
||||
print(error_message)
|
||||
data = None
|
||||
except TypeError as error_message:
|
||||
print("Type Error", error_message)
|
||||
data = None
|
||||
else:
|
||||
if "msg" in data.keys() and data['msg'] != "No error":
|
||||
raise ValueError("Error from ADSBX: msg = ", data['msg'])
|
||||
if "ctime" in data.keys():
|
||||
data_ctime = float(data['ctime']) / 1000.0
|
||||
print("Data ctime:",datetime.utcfromtimestamp(data_ctime))
|
||||
if "now" in data.keys():
|
||||
data_now = float(data['now']) / 1000.0
|
||||
print("Data now time:",datetime.utcfromtimestamp(data_now))
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
if "msg" in data.keys() and data['msg'] != "No error":
|
||||
raise ValueError("Error from ADSBX: msg = ", data['msg'])
|
||||
if "ctime" in data.keys():
|
||||
data_ctime = float(data['ctime']) / 1000.0
|
||||
print("Data ctime:",datetime.utcfromtimestamp(data_ctime))
|
||||
if "now" in data.keys():
|
||||
data_now = float(data['now']) / 1000.0
|
||||
print("Data now time:",datetime.utcfromtimestamp(data_now))
|
||||
print("Current UTC:", datetime.utcnow())
|
||||
else:
|
||||
data = None
|
||||
return data
|
||||
return data
|
||||
except Exception as e:
|
||||
print('Error calling RapidAPI', e)
|
||||
return None
|
||||
|
|
|
|||
Loading…
Reference in New Issue