README / app.py
alaskavix12's picture
init
63cca97
Raw History Blame Contribute Delete
693 Bytes
from fastapi import FastAPI
from contextlib import asynccontextmanager
import logging
from bot import clientbot
from subprocess import Popen
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info("Starting up...")
app.state.bot = await clientbot()
# Set up auto-alive
logger.info("Set up auto Alive...")
Popen(["python", "alive.py"])
yield
logger.info("Shutting down...")
await app.state.bot.stop()
app = FastAPI(lifespan=lifespan)
@app.get("/")
async def root():
logger.info("Received root request")
return {"message": "Hello, World!"}