-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
35 lines (28 loc) · 970 Bytes
/
server.py
File metadata and controls
35 lines (28 loc) · 970 Bytes
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
import os
from dotenv import load_dotenv
import asyncio
from fastapi import FastAPI
import telethon
import logging
import uvicorn
load_dotenv()
logger = logging.getLogger(__name__)
app = FastAPI()
@app.get("/balance")
async def get_balance():
client = telethon.TelegramClient(session='session', api_id=os.getenv('api_id'), api_hash=os.getenv('api_hash'))
await client.connect()
if not await client.is_user_authorized():
return {'message': 'session is not authorized'}
bot_username = 'hyperpool_bot'
event = await client.send_message(bot_username, '/balance')
await asyncio.sleep(1)
result = {}
async for message in client.iter_messages(bot_username, limit=1):
data = message.text.split('\n')
result['balance'] = data[0].split(': ')[2]
result['shares'] = data[1].split(': ')[1]
await client.disconnect()
return result
if __name__ == "__main__":
uvicorn.run('server:app', host="localhost")