Download app.py from danicor/danitell2: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/danicor/danitell2/resolve/main/app.py
- Command line
-
hf download hf://spaces/danicor/danitell2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/danicor/danitell2/resolve/main/app.py
1.72 kB
| import os | |
| import asyncio | |
| from telethon import TelegramClient, events | |
| # =============================== | |
| # Telegram credentials (ENV) | |
| # =============================== | |
| API_ID = int(os.environ["API_ID"]) | |
| API_HASH = os.environ["API_HASH"] | |
| BOT_TOKEN = os.environ["BOT_TOKEN"] | |
| # =============================== | |
| # Persistent storage | |
| # =============================== | |
| UPLOAD_DIR = "/data/uploads" | |
| os.makedirs(UPLOAD_DIR, exist_ok=True) | |
| # =============================== | |
| # Telegram Client (IPv4 forced) | |
| # =============================== | |
| client = TelegramClient( | |
| "bot", | |
| API_ID, | |
| API_HASH, | |
| connection_retries=10, | |
| timeout=30, | |
| use_ipv6=False | |
| ) | |
| # =============================== | |
| # Handlers | |
| # =============================== | |
| async def start_handler(event): | |
| await event.reply( | |
| "🤖 Bot is online.\n" | |
| "هر فایلی بفرستی، روی HuggingFace ذخیره میکنم." | |
| ) | |
| async def file_handler(event): | |
| if not event.file: | |
| return | |
| try: | |
| file_path = await event.download_media(file=UPLOAD_DIR) | |
| await event.reply( | |
| "✅ فایل ذخیره شد\n\n" | |
| f"📂 مسیر:\n{file_path}" | |
| ) | |
| print(f"Saved: {file_path}") | |
| except Exception as e: | |
| await event.reply(f"❌ خطا:\n{e}") | |
| print("Download error:", e) | |
| # =============================== | |
| # Main loop | |
| # =============================== | |
| async def main(): | |
| print("Starting Telegram bot...") | |
| await client.start(bot_token=BOT_TOKEN) | |
| print("Connected to Telegram") | |
| await client.run_until_disconnected() | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |