Spaces:
Runtime error
Runtime error
import logging | |
import asyncio | |
from aiohttp import web | |
import asyncio | |
from telethon import TelegramClient | |
from src.Classes.Hander import Handler | |
import os | |
routes = web.RouteTableDef() | |
API_ID=os.environ.get("API_ID") | |
API_HASH=os.environ.get("API_HASH") | |
BOT_TOKEN=os.environ.get("BOT_TOKEN") | |
client = TelegramClient("stream_bot", API_ID, API_HASH) | |
async def get_status(req: web.Request): | |
return web.json_response(data={"status": "working"}, status=200) | |
async def handle_get_request(req: web.Request) -> web.Response: | |
hander = Handler(req=req, client=client) | |
hander.route = "inline" | |
return await hander.process_request() | |
async def handle_get_request(req: web.Request) -> web.Response: | |
hander = Handler(req=req, client=client) | |
hander.head = True | |
hander.route = "attachment" | |
return await hander.process_request() | |
async def handle_get_request(req: web.Request) -> web.Response: | |
hander = Handler(req=req, client=client) | |
hander.route = "attachment" | |
return await hander.process_request() | |
async def main(): | |
port = int(os.environ.get("PORT", "7860")) | |
await client.start(bot_token=BOT_TOKEN) | |
server = web.Application() | |
server.add_routes(routes) | |
runner = web.AppRunner(server) | |
await runner.setup() | |
await web.TCPSite(runner, port=port).start() | |
if __name__ == "__main__": | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main()) | |
loop.run_forever() | |