You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.0 KiB
48 lines
1.0 KiB
import collections |
|
import sqlite3 |
|
import time |
|
|
|
Subscription = collections.namedtuple( |
|
"Subscription", |
|
[ |
|
"id", |
|
"phone", |
|
"icao", |
|
"description", |
|
"last_seen", |
|
"platform", |
|
], |
|
) |
|
|
|
|
|
def load_database(file_name): |
|
con = sqlite3.connect(file_name) |
|
|
|
cur = con.execute( |
|
"CREATE TABLE IF NOT EXISTS subscriptions(phone VARCHAR, icao VARCHAR, description VARCHAR, last_seen INTEGER)" |
|
) |
|
|
|
try: |
|
cur.execute( |
|
"ALTER TABLE subscriptions ADD COLUMN platform DEFAULT 'textbelt'" |
|
) |
|
except sqlite3.OperationalError: |
|
pass |
|
|
|
con.commit() |
|
|
|
return con |
|
|
|
|
|
def update_last_seen_time(con, sub_id): |
|
con.execute( |
|
"UPDATE subscriptions SET last_seen = ? WHERE rowid = ?", |
|
(time.time(), sub_id), |
|
) |
|
|
|
|
|
def get_subscriptions(con): |
|
for subscription in con.execute( |
|
"SELECT rowid, phone, icao, description, last_seen, platform FROM subscriptions" |
|
).fetchall(): |
|
yield Subscription(*subscription)
|
|
|