summaryrefslogtreecommitdiff
path: root/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to '__main__.py')
-rw-r--r--__main__.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/__main__.py b/__main__.py
index deacefa..7ae3047 100644
--- a/__main__.py
+++ b/__main__.py
@@ -1,9 +1,28 @@
+import os.path
+import sqlite3
+from pathlib import Path
+
+from contextlib import asynccontextmanager
from typing import Annotated
from fastapi import FastAPI, Depends, Request
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
-app = FastAPI()
+from .config import Config
+
+
+sq_con = None
+
+@asynccontextmanager
+async def lifespan(app: FastAPI):
+ db_dir = os.path.dirname(Config.DATABASE_PATH)
+ Path(db_dir).mkdir(parents=True, exist_ok=True)
+
+ sq_con = sqlite3.connect(Config.DATABASE_PATH)
+ yield
+
+
+app = FastAPI(lifespan=lifespan)
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")