️ Catching not images

Also got rid of the sleep
This commit is contained in:
2021-04-06 23:37:53 +03:00
parent 35a35ab9b1
commit d90b4a1b18
2 changed files with 6 additions and 5 deletions

View File

@@ -79,7 +79,7 @@ while True:
photos_saved += 1
save_photo(image_url)
sleep(1)
#sleep(1)
except KeyboardInterrupt:
c.print(' Goodbye!', style='blue')

View File

@@ -7,7 +7,8 @@ def detect(url):
response = requests.get(url)
try:
img = Image.open(io.BytesIO(response.content))
except OSError:
return ''
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 pytesseract.image_to_string(img, lang='rus', timeout=30).lower()
return string