Browse Source

Initial commit

main
Samuel Sloniker 1 year ago
parent
commit
17be4ca095
  1. 3
      .gitignore
  2. 61
      adsms.py
  3. 10
      example_config.json
  4. 1
      requirements.txt

3
.gitignore vendored

@ -152,3 +152,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
config.json
subscriptions.db
pid.txt

61
adsms.py

@ -0,0 +1,61 @@
import os
import time
import json
import sqlite3
import argparse
import requests
parser = argparse.ArgumentParser()
parser.add_argument("config_file")
args = parser.parse_args()
with open(args.config_file) as f:
config = json.load(f)
try:
if config["pid_file"]:
with open(config["pid_file"], "w+") as f:
f.write(str(os.getpid()))
con = sqlite3.connect(config["database"])
con.execute(
"CREATE TABLE IF NOT EXISTS subscriptions(phone VARCHAR, icao VARCHAR, description VARCHAR, last_seen INTEGER)"
)
con.commit()
while True:
response = requests.get(config["data"])
planes = response.json()["aircraft"]
data = {plane["hex"]: plane for plane in planes}
cur = con.execute(
"SELECT rowid, phone, icao, description, last_seen FROM subscriptions"
)
for sub_id, phone, icao, description, last_seen in cur.fetchall():
if icao in data and data[icao]["seen"] < config["max_age"]:
if last_seen + config["min_disappearance"] < time.time():
message = f"{description}\n{config['tracker']}?icao={icao}"
request = {
"phone": phone,
"message": message,
"key": config["textbelt_key"],
}
resp = requests.post("https://textbelt.com/text", request)
print(f"{phone}: {message}")
print(resp.json())
con.execute(
"UPDATE subscriptions SET last_seen = ? WHERE rowid = ?",
(time.time(), sub_id),
)
con.commit()
time.sleep(config["delay"])
finally:
if config["pid_file"]:
os.unlink(config["pid_file"])

10
example_config.json

@ -0,0 +1,10 @@
{
"textbelt_key": "",
"data": "http://localhost/tar1090/data/aircraft.json",
"tracker": "https://globe.theairtraffic.com/",
"database": "subscriptions.db",
"pid_file": "pid.txt",
"max_age": 30,
"min_disappearance": 120,
"delay": 1
}

1
requirements.txt

@ -0,0 +1 @@
requests
Loading…
Cancel
Save