|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from uuid import uuid4
|
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
|
|
@ -18,16 +19,17 @@ cur = con.cursor() # NB! single is enough for now, we might require multiple la
|
|
|
|
|
async def new_session():
|
|
|
|
|
"""Start a new session"""
|
|
|
|
|
# add session to the database
|
|
|
|
|
time = datetime.utcnow().replace(microsecond=0).isoformat()
|
|
|
|
|
tries = 3 # something is very wrong with our random, if we miss 3 times
|
|
|
|
|
for i in range(tries):
|
|
|
|
|
try:
|
|
|
|
|
# generate a cookie
|
|
|
|
|
cookie = uuid4().hex
|
|
|
|
|
cur.execute(
|
|
|
|
|
"""INSERT INTO sessions(cookie)
|
|
|
|
|
VALUES(:cookie)
|
|
|
|
|
"""INSERT INTO sessions(cookie, time)
|
|
|
|
|
VALUES(:cookie, :time)
|
|
|
|
|
""",
|
|
|
|
|
{"cookie": cookie},
|
|
|
|
|
{"cookie": cookie, "time": time},
|
|
|
|
|
)
|
|
|
|
|
con.commit()
|
|
|
|
|
except sqlite3.IntegrityError as e:
|
|
|
|
|
|