-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsqlite3.py
More file actions
51 lines (46 loc) · 2.5 KB
/
sqlite3.py
File metadata and controls
51 lines (46 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
#!/usr/bin/env python
from contextlib import closing
import sqlite3
import time
from .config import SQLITE3_DB
def get_status(uid):
with closing(sqlite3.connect(SQLITE3_DB)) as connection:
with closing(connection.cursor()) as cursor:
cursor.execute("create table if not exists metalogo_server (uid TEXT primary key, status TEXT, created INTEGER, finished INTEGER )")
rows = cursor.execute(f"SELECT uid, status FROM metalogo_server WHERE uid = '{uid}'").fetchall()
if len(rows) == 1:
return rows[0][1]
else:
return 'not found'
def get_create_time(uid):
with closing(sqlite3.connect(SQLITE3_DB)) as connection:
with closing(connection.cursor()) as cursor:
cursor.execute("create table if not exists metalogo_server (uid TEXT primary key, status TEXT, created INTEGER, finished INTEGER )")
rows = cursor.execute(f"SELECT uid, created FROM metalogo_server WHERE uid = '{uid}'").fetchall()
if len(rows) == 1:
return rows[0][1]
else:
return -1
def get_finished_time(uid):
with closing(sqlite3.connect(SQLITE3_DB)) as connection:
with closing(connection.cursor()) as cursor:
cursor.execute("create table if not exists metalogo_server (uid TEXT primary key, status TEXT, created INTEGER, finished INTEGER )")
rows = cursor.execute(f"SELECT uid, finished FROM metalogo_server WHERE uid = '{uid}'").fetchall()
if len(rows) == 1:
return rows[0][1]
else:
return -1
def write_status(uid,status,db=SQLITE3_DB):
with closing(sqlite3.connect(db)) as connection:
with closing(connection.cursor()) as cursor:
cursor.execute("create table if not exists metalogo_server (uid TEXT primary key, status TEXT, created INTEGER, finished INTEGER )")
rows = cursor.execute(f"SELECT uid, status FROM metalogo_server WHERE uid = '{uid}'").fetchall()
if len(rows) == 1:
if status == 'finished':
cursor.execute(f"UPDATE metalogo_server SET status = '{status}', finished = {round(time.time())} where uid = '{uid}' ")
else:
cursor.execute(f"UPDATE metalogo_server SET status = '{status}' where uid = '{uid}' ")
else:
cursor.execute(f"INSERT INTO metalogo_server VALUES ('{uid}','{status}',{round(time.time())},-1) ")
connection.commit()