Files
dochunt/utils/detect.py
Anatoly d90b4a1b18 ️ Catching not images
Also got rid of the sleep
2021-04-06 23:37:53 +03:00

15 lines
401 B
Python

import pytesseract
from PIL import Image
import io
import requests
def detect(url):
response = requests.get(url)
try:
img = Image.open(io.BytesIO(response.content))
string = pytesseract.image_to_string(img, lang='rus', timeout=30).lower()
except OSError: # Happens when whatever we get is not an image and cant be opened as such
string = ''
return string