-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (35 loc) · 1.07 KB
/
main.py
File metadata and controls
48 lines (35 loc) · 1.07 KB
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
import json
from telethon import TelegramClient, events
from pytesseract import image_to_string
from PIL import Image
import requests
from decouple import config
api_id = config('API_ID')
api_hash = config('API_HASH')
client = TelegramClient('botdb', api_id, api_hash)
headers = {
'Content-Type': 'application/json'
}
async def read_image():
print('reading image')
return image_to_string(Image.open('images/image.png'))
async def send_text(text, img):
data = dict(
text=text,
img=img
)
data = json.dumps(data)
requests.post('http://localhost:5000/binance', headers=headers, data=data)
@client.on(events.NewMessage(chats='testalv'))
async def my_event_handler(msg):
# If the message has a media, it downloads it
if msg.media is not None:
await client.download_media(msg.media, 'images/image.png')
print('Image saved')
text = await read_image()
await send_text(text, True)
else:
text = msg.message.message
await send_text(text, False)
client.start()
client.run_until_disconnected()