File size: 1,164 Bytes
222f19c
4b81f85
222f19c
3140238
4b81f85
 
 
 
222f19c
 
 
3140238
 
4b81f85
3140238
4b81f85
3140238
222f19c
4b81f85
3140238
222f19c
4b81f85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222f19c
4b81f85
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# main.py

import uvicorn
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import logging
import asyncio
import bot  # import your bot.py file

app = FastAPI()

@app.on_event("startup")
async def startup_event():
    logging.basicConfig(level=logging.INFO)
    logging.info("Starting bot polling in background...")
    asyncio.create_task(bot.run_bot())

@app.get("/health")
def health():
    return {"status": "ok"}

@app.get("/")
def home():
    active_workers = bot.config.CONCURRENT_WORKERS
    running_batches = len(bot.BATCH_JOBS)
    queued_tasks = bot.TASK_QUEUE.qsize()

    html = f"""
    <html>
    <head><title>Terabox Bot Status</title></head>
    <body>
        <h1>Terabox Bot Status</h1>
        <p><b>Bot Username:</b> {bot.bot_username or 'Unknown'}</p>
        <p><b>Active Workers:</b> {active_workers}</p>
        <p><b>Running Batches:</b> {running_batches}</p>
        <p><b>Queued Tasks:</b> {queued_tasks}</p>
        <p><b>Health:</b> <a href="/health">/health</a></p>
    </body>
    </html>
    """
    return HTMLResponse(content=html)

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)