-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rapidapi' of https://github.com/makrsmark/plane-notify …
…into multi
- Loading branch information
Showing
4 changed files
with
128 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import requests | ||
import json | ||
import configparser | ||
from datetime import datetime | ||
|
||
main_config = configparser.ConfigParser() | ||
main_config.read('./configs/mainconf.ini') | ||
api_version = main_config.get('RpdADSBX', 'API_VERSION') | ||
|
||
def pull_rpdadsbx(planes): | ||
api_version = int(main_config.get('RpdADSBX', 'API_VERSION')) | ||
if api_version != 2: | ||
raise ValueError("Bad RapidAPI ADSBX API Version") | ||
url = "https://adsbexchange-com1.p.rapidapi.com/v2/icao/" + planes + "/" | ||
headers = { | ||
"X-RapidAPI-Host": "adsbexchange-com1.p.rapidapi.com", | ||
"X-RapidAPI-Key": main_config.get('RpdADSBX', 'API_KEY') | ||
} | ||
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)) | ||
print("Current UTC:", datetime.utcnow()) | ||
else: | ||
data = None | ||
return data |