38 lines
743 B
Python
38 lines
743 B
Python
import time
|
|
import json
|
|
import sqlite3
|
|
from config import DB_PATH
|
|
|
|
def get_student_by_token(token: str):
|
|
conn = sqlite3.connect(DB_PATH)
|
|
cur = conn.cursor()
|
|
|
|
cur.execute(
|
|
"SELECT raw_json FROM student WHERE token = ?",
|
|
(token,),
|
|
)
|
|
row = cur.fetchone()
|
|
conn.close()
|
|
|
|
if not row:
|
|
return None
|
|
|
|
return json.loads(row[0])
|
|
|
|
|
|
def save_student(token: str, student: dict):
|
|
conn = sqlite3.connect(DB_PATH)
|
|
cur = conn.cursor()
|
|
|
|
cur.execute(
|
|
"""
|
|
INSERT OR REPLACE INTO student
|
|
(token, raw_json, updated_at)
|
|
VALUES (?, ?, ?)
|
|
""",
|
|
(token, json.dumps(student, ensure_ascii=False), int(time.time())),
|
|
)
|
|
|
|
conn.commit()
|
|
conn.close()
|