Spaces:
Paused
Paused
fix: req.txt modified
Browse files- app.py +23 -12
- requirements.txt +5 -5
app.py
CHANGED
|
@@ -1,15 +1,26 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
| 2 |
from bot_telegram import init_bot
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
bot = init_bot()
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
from bot_telegram import init_bot
|
| 5 |
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
bot = None
|
| 8 |
+
|
| 9 |
+
@app.on_event("startup")
|
| 10 |
+
async def startup_event():
|
| 11 |
+
"""Start the Telegram bot when the FastAPI application starts."""
|
| 12 |
+
global bot
|
| 13 |
bot = init_bot()
|
| 14 |
+
await bot.run()
|
| 15 |
+
|
| 16 |
+
@app.on_event("shutdown")
|
| 17 |
+
async def shutdown_event():
|
| 18 |
+
"""Stop the Telegram bot when the FastAPI application stops."""
|
| 19 |
+
global bot
|
| 20 |
+
if bot:
|
| 21 |
+
logging.info("Stopping bot...")
|
| 22 |
+
await bot.bot_stop()
|
| 23 |
+
|
| 24 |
+
@app.get("/")
|
| 25 |
+
def greet_json():
|
| 26 |
+
return {"Hello": "World!"}
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
python-telegram-bot
|
| 2 |
-
requests
|
| 3 |
-
aiohttp
|
| 4 |
-
fastapi
|
| 5 |
-
uvicorn[standard]
|
|
|
|
| 1 |
+
python-telegram-bot
|
| 2 |
+
requests
|
| 3 |
+
aiohttp
|
| 4 |
+
fastapi
|
| 5 |
+
uvicorn[standard]
|