Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,43 +1,47 @@
|
|
| 1 |
# main.py
|
| 2 |
|
| 3 |
import logging
|
|
|
|
| 4 |
import uvicorn
|
| 5 |
from fastapi import FastAPI
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
from bot import start_bot
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
title="Terabox Downloader Bot API",
|
| 15 |
-
version="1.0.0"
|
| 16 |
)
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
@app.on_event("startup")
|
| 21 |
async def startup_event():
|
| 22 |
logger.info("Starting bot polling in background...")
|
| 23 |
-
asyncio.create_task(dp.start_polling(
|
| 24 |
-
|
| 25 |
-
@app.get("/",
|
| 26 |
-
async def
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
"
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
}
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
|
|
|
| 43 |
uvicorn.run("main:app", host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
# main.py
|
| 2 |
|
| 3 |
import logging
|
| 4 |
+
import asyncio
|
| 5 |
import uvicorn
|
| 6 |
from fastapi import FastAPI
|
| 7 |
+
from fastapi.responses import HTMLResponse
|
|
|
|
| 8 |
from bot import start_bot
|
| 9 |
|
| 10 |
+
# --- Setup ---
|
| 11 |
+
logging.basicConfig(
|
| 12 |
+
level=logging.INFO,
|
| 13 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
|
|
|
|
|
| 14 |
)
|
| 15 |
|
| 16 |
+
logger = logging.getLogger("main")
|
| 17 |
+
|
| 18 |
+
app = FastAPI()
|
| 19 |
+
|
| 20 |
+
# Start bot
|
| 21 |
+
dp, bot_instance = start_bot()
|
| 22 |
|
| 23 |
@app.on_event("startup")
|
| 24 |
async def startup_event():
|
| 25 |
logger.info("Starting bot polling in background...")
|
| 26 |
+
asyncio.create_task(dp.start_polling(bot_instance))
|
| 27 |
+
|
| 28 |
+
@app.get("/", response_class=HTMLResponse)
|
| 29 |
+
async def root():
|
| 30 |
+
html_content = """
|
| 31 |
+
<html>
|
| 32 |
+
<head><title>Terabox Bot Status</title></head>
|
| 33 |
+
<body style="font-family:sans-serif;">
|
| 34 |
+
<h1>✅ Terabox Bot is Running</h1>
|
| 35 |
+
<p>You can check /health endpoint too.</p>
|
| 36 |
+
</body>
|
| 37 |
+
</html>
|
| 38 |
+
"""
|
| 39 |
+
return HTMLResponse(content=html_content)
|
| 40 |
+
|
| 41 |
+
@app.get("/health")
|
| 42 |
+
async def health():
|
| 43 |
+
return {"status": "ok", "bot": "running"}
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
+
logger.info("===== Application Startup =====")
|
| 47 |
uvicorn.run("main:app", host="0.0.0.0", port=7860)
|