Spaces:
Runtime error
Runtime error
File size: 1,561 Bytes
00c68f3 bd57d1d 00c68f3 fea1da5 bd57d1d 00c68f3 |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
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)
@routes.get(r"/")
async def get_status(req: web.Request):
return web.json_response(data={"status": "working"}, status=200)
@routes.get(r"/stream/{id:\d+}")
async def handle_get_request(req: web.Request) -> web.Response:
hander = Handler(req=req, client=client)
hander.route = "inline"
return await hander.process_request()
@routes.head(r"/download/{id:\d+}")
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()
@routes.get(r"/download/{id:\d+}")
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()
|