AstraOS commited on
Commit
e1bee2a
Β·
verified Β·
1 Parent(s): e2a22c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -26
app.py CHANGED
@@ -454,34 +454,64 @@ def execute_command(message):
454
 
455
 
456
  # ─────────────────────────────────────────────────── FastAPI ───
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  app = FastAPI()
458
 
459
- @app.get("/")
460
- def root(): # β‘‘ health‑check hits this β†’ must return 200 quickly
461
- # return {"status": "ok"}
462
- return RedirectResponse(
463
- url="https://t.me/python3463_bot",
464
- status_code=status.HTTP_302_FOUND # 302 is fine too
465
- )
466
- # html_content = """
467
- # <!DOCTYPE html>
468
- # <html>
469
- # <head>
470
- # <title>Telegram Bot Preview</title>
471
- # <meta property="og:title" content="Join the Python Bot" />
472
- # <meta property="og:description" content="Click to chat with the Python Bot on Telegram." />
473
- # <meta property="og:url" content="https://t.me/python3463_bot" />
474
- # <meta property="og:type" content="website" />
475
- # <meta property="og:image" content="https://telegram.org/img/t_logo.png" />
476
- # </head>
477
- # <body>
478
- # <h1>Open Telegram Bot</h1>
479
- # <p><a href="https://t.me/python3463_bot" target="_blank">Click here to open the bot</a></p>
480
- # <iframe src="https://t.me/python3463_bot" width="100%" height="500px" style="border:none;"></iframe>
481
- # </body>
482
- # </html>
483
- # """
484
- # return HTMLResponse(content=html_content)
 
 
485
 
486
  @app.on_event("startup")
487
  def startup():
 
454
 
455
 
456
  # ─────────────────────────────────────────────────── FastAPI ───
457
+ # app = FastAPI()
458
+
459
+ # @app.get("/")
460
+ # def root(): # β‘‘ health‑check hits this β†’ must return 200 quickly
461
+ # # return {"status": "ok"}
462
+ # return RedirectResponse(
463
+ # url="https://t.me/python3463_bot",
464
+ # status_code=status.HTTP_302_FOUND # 302 is fine too
465
+ # )
466
+ CACHE_TTL = 60 * 60 # 1Β hour
467
+ CACHE = {}
468
+
469
+ BOT_USERNAME = "python3463_bot"
470
+ TME_URL = f"https://t.me/{BOT_USERNAME}"
471
+
472
+ def get_avatar_url() -> str | None:
473
+ now = time.time()
474
+ if "photo" in CACHE and now - CACHE["ts"] < CACHE_TTL:
475
+ return CACHE["photo"]
476
+
477
+ html = requests.get(TME_URL, timeout=5).text
478
+ m = re.search(r'<meta property="og:image" content="([^"]+)"', html)
479
+ if m:
480
+ CACHE["photo"] = m.group(1)
481
+ CACHE["ts"] = now
482
+ return CACHE["photo"]
483
+ return None
484
+
485
  app = FastAPI()
486
 
487
+ @app.get("/", include_in_schema=False)
488
+ def root():
489
+ photo = get_avatar_url() or "/static/telegram.png"
490
+ html = f"""
491
+ <html>
492
+ <head>
493
+ <title>Pythonβ€―Bot</title>
494
+ <style>
495
+ body{{font-family:sans-serif;display:flex;justify-content:center;}}
496
+ .card{{max-width:420px;padding:24px;border-radius:12px;
497
+ box-shadow:0 4px 12px rgba(0,0,0,.1);text-align:center;}}
498
+ img{{border-radius:50%;width:120px;height:120px;object-fit:cover;}}
499
+ a.btn{{background:#2AABEE;color:#fff;padding:12px 24px;border-radius:8px;
500
+ text-decoration:none;font-weight:bold;display:inline-block;margin-top:12px;}}
501
+ </style>
502
+ </head>
503
+ <body>
504
+ <div class="card">
505
+ <img src="{photo}" alt="Bot Avatar">
506
+ <h2>PythonΒ Bot</h2>
507
+ <p><strong>@{BOT_USERNAME}</strong></p>
508
+ <p>The fastest way to practise PythonΒ 3.</p>
509
+ <a class="btn" href="https://t.me/{BOT_USERNAME}" target="_blank">StartΒ Bot</a>
510
+ </div>
511
+ </body>
512
+ </html>
513
+ """
514
+ return HTMLResponse(html)
515
 
516
  @app.on_event("startup")
517
  def startup():