Skip to content

Commit

Permalink
Added a delay to avoid hitting Google's limit of 600 requests per min…
Browse files Browse the repository at this point in the history
…ute.
  • Loading branch information
Zarxrax authored May 12, 2018
1 parent c3bdbcc commit abcab98
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions PNG2SRT.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
import sys
import time
import argparse
from io import BytesIO
from PIL import Image, ImageOps
Expand Down Expand Up @@ -114,11 +115,14 @@ def ocr_text(filenames):
resp = requests.post(VISION_ENDPOINT, data=data, params={"key": AUTH_KEY}, headers={'Content-Type': 'application/json'})
#open("output.json","wb").write(resp.text.encode('utf-8'))

for idx, r in enumerate(resp.json()['responses']):
#open("output_%d.json" % idx,"wb").write(json.dumps(r, indent=4, ensure_ascii=False, encoding="utf-8").encode('utf-8'))

if 'textAnnotations' in r:
output[requested_filenames[idx]] = r['textAnnotations'][0]['description']#.encode('utf8') # First entry is always the "final" output
try:
for idx, r in enumerate(resp.json()['responses']):
#open("output_%d.json" % idx,"wb").write(json.dumps(r, indent=4, ensure_ascii=False).encode('utf-8'))
if 'textAnnotations' in r:
output[requested_filenames[idx]] = r['textAnnotations'][0]['description']#.encode('utf8') # First entry is always the "final" output
time.sleep(0.2)
except KeyError:
print(resp.text.encode('utf-8'))

return output

Expand Down

0 comments on commit abcab98

Please sign in to comment.