feat: 第一次上传
This commit is contained in:
39
services/student_cache.py
Normal file
39
services/student_cache.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import time
|
||||
import json
|
||||
import sqlite3
|
||||
|
||||
DB_PATH = "data.db"
|
||||
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user