Samuel Sloniker
1 year ago
2 changed files with 43 additions and 26 deletions
@ -0,0 +1,37 @@ |
|||||||
|
import collections |
||||||
|
|
||||||
|
Subscription = collections.namedtuple( |
||||||
|
"Subscription", |
||||||
|
[ |
||||||
|
"id", |
||||||
|
"phone", |
||||||
|
"icao", |
||||||
|
"description", |
||||||
|
"last_seen", |
||||||
|
], |
||||||
|
) |
||||||
|
|
||||||
|
|
||||||
|
def load_database(file_name): |
||||||
|
con = sqlite3.connect(file_name) |
||||||
|
|
||||||
|
con.execute( |
||||||
|
"CREATE TABLE IF NOT EXISTS subscriptions(phone VARCHAR, icao VARCHAR, description VARCHAR, last_seen INTEGER)" |
||||||
|
) |
||||||
|
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 FROM subscriptions" |
||||||
|
).fetchall(): |
||||||
|
return Subscription(*subscription) |
Loading…
Reference in new issue