Initial commit
This commit is contained in:
parent
39ffdab46f
commit
17be4ca095
3
.gitignore
vendored
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
Normal file
61
adsms.py
Normal file
|
@ -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
Normal file
10
example_config.json
Normal file
|
@ -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
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
requests
|
Loading…
Reference in New Issue
Block a user