understanding commited on
Commit
41fd54e
·
verified ·
1 Parent(s): 3ea3805

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +31 -27
main.py CHANGED
@@ -1,43 +1,47 @@
1
  # main.py
2
 
3
  import logging
 
4
  import uvicorn
5
  from fastapi import FastAPI
6
- import asyncio
7
-
8
  from bot import start_bot
9
 
10
- logging.basicConfig(level=logging.INFO)
11
- logger = logging.getLogger(__name__)
12
-
13
- app = FastAPI(
14
- title="Terabox Downloader Bot API",
15
- version="1.0.0"
16
  )
17
 
18
- dp, bot = start_bot()
 
 
 
 
 
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(bot))
24
-
25
- @app.get("/", tags=["root"])
26
- async def read_root():
27
- return {
28
- "message": "✅ Terabox Downloader Bot is running!",
29
- "workers": "4", # You can even dynamically count your workers
30
- "status": "OK"
31
- }
32
-
33
- @app.get("/health", tags=["health"])
34
- async def health_check():
35
- return {
36
- "status": "ok",
37
- "bot_username": (await bot.me()).username,
38
- "forward_channel": f"{bot.id}",
39
- "version": "1.0.0"
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)