File size: 693 Bytes
63cca97 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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!"}
|