From d90b4a1b180595ead4883c804403eb2b34c75260 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Tue, 6 Apr 2021 23:37:53 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Catching=20not=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also got rid of the sleep --- main.py | 2 +- utils/detect.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 3c2ebfc..4aacbed 100644 --- a/main.py +++ b/main.py @@ -79,7 +79,7 @@ while True: photos_saved += 1 save_photo(image_url) - sleep(1) + #sleep(1) except KeyboardInterrupt: c.print(' Goodbye!', style='blue') diff --git a/utils/detect.py b/utils/detect.py index e501c64..074c5ef 100644 --- a/utils/detect.py +++ b/utils/detect.py @@ -7,7 +7,8 @@ def detect(url): response = requests.get(url) try: img = Image.open(io.BytesIO(response.content)) - except OSError: - return '' - - return pytesseract.image_to_string(img, lang='rus', timeout=30).lower() + 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