Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
Fix retry bug
Browse files Browse the repository at this point in the history
Has been reported at googleapis/python-vision#31
  • Loading branch information
Jay Turner committed Jun 28, 2020
1 parent 9d02a16 commit 2ee1cdd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 14 additions & 2 deletions PogoOCR/cloudvision.py
Expand Up @@ -18,5 +18,17 @@ def __init__(self, service_file, image_content=None, image_uri=None):

def get_text(self):
print("Requesting TEXT_DETECTION from Google Cloud API. This will cost us 0.0015 USD.")
response = self.google.text_detection(image=self.image, retry=5)
self.text_found = response.text_annotations
attempts = 0
while attempts < 5:
attempts += 1
response = self.google.text_detection(image=self.image)
try:
response.text_annotations[0]
except IndexError:
pass
else:
self.text_found = response.text_annotations
break

if attempts == 5:
raise Exception(response.text_annotations)
12 changes: 6 additions & 6 deletions setup.py
@@ -1,16 +1,16 @@
import setuptools
import re
from setuptools import setup

with open('README.md') as f:
with open('README.md', 'r') as f:
readme = f.read()

with open('PogoOCR/__init__.py') as f:
with open('PogoOCR/__init__.py', 'r') as f:
version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read()).group(1)

with open('requirements.txt') as f:
requirements = f.splitlines()
with open('requirements.txt', 'r') as f:
requirements = f.read().splitlines()

setup(
setuptools.setup(
name="PogoOCR",
version=version,
author="Jay Turner",
Expand Down

0 comments on commit 2ee1cdd

Please sign in to comment.