-
Notifications
You must be signed in to change notification settings - Fork 2
/
htr_bot.py
47 lines (36 loc) · 1.36 KB
/
htr_bot.py
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
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 15 00:00:12 2019
@author: tanma
"""
import cv2
import logging
import pytesseract
import urllib.request
from telegram.ext import Updater, MessageHandler, Filters
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
def download_image(url,name):
fullname = str(name)+".jpeg"
urllib.request.urlretrieve(url,fullname)
def some_func(bot, update):
pass
if not update.effective_message.photo:
update.effective_message.reply_text(text = "This bot is only capable of Computer Vision Tasks!")
update.effective_message.reply_text(text = "Getting Self Aware Now!")
else:
msg = update.effective_message
file_id = msg.photo[-1].file_id
photo = bot.get_file(file_id)
download_image(photo["file_path"],'wassup')
text = pytesseract.image_to_string(cv2.imread("wassup.jpeg"), lang = "eng")
update.effective_message.reply_text(text = text)
def main():
updater = Updater('1059913469:AAHPrHeLuqVEz-UbRezjyYJQ_swoHrQ-_QM')
dp = updater.dispatcher
dp.add_handler(MessageHandler(Filters.all, some_func))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()