Skip to content

Commit

Permalink
Add delay between requests (#22)
Browse files Browse the repository at this point in the history
Add delay between requests to avoid hitting Google Translate API limits
  • Loading branch information
gyund committed Jun 5, 2023
1 parent f47f89a commit c09b476
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/translations.py
Expand Up @@ -6,6 +6,7 @@
import re
import sys
import typing
import time

import xml.etree.ElementTree as ET
import googletrans
Expand Down Expand Up @@ -135,6 +136,10 @@ def _translate(
if num_translated % 10 == 0:
logging.info("Num translated: %d/%d", num_translated, len(src_strings))

# sleep to avoid hitting Google Translation API's rate limits
if num_translated > 1:
time.sleep(0.7)

logging.info(
"Translated %d strings to (%s, %s)",
num_translated,
Expand Down

0 comments on commit c09b476

Please sign in to comment.