summaryrefslogtreecommitdiff
path: root/__main__.py
blob: 55fa74008bbb67230536aeaa4f59293a0409dbe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from contextlib import asynccontextmanager

from fastapi import FastAPI

from .apirouters import auth, tasks, customize_ship
from .modules.database import cursor, conn


@asynccontextmanager
async def lifespan(application: FastAPI):
    cursor.execute(
        "CREATE TABLE IF NOT EXISTS agents(primary_key INTEGER PRIMARY KEY, callsign TEXT NOT NULL UNIQUE, token TEXT NOT NULL)")
    cursor.execute(
        "CREATE TABLE IF NOT EXISTS ships(primary_key INTEGER PRIMARY KEY, symbol TEXT NOT NULL UNIQUE, task TEXT NOT NULL, params TEXT, name TEXT)")
    conn.commit()
    auth.load_agents_from_database()
    yield


app = FastAPI(lifespan=lifespan)
app.include_router(auth.router)
app.include_router(tasks.router)
app.include_router(customize_ship.router)