Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 30, 2024
1 parent 7e97489 commit 46f53c3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions deepl/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ async def __translate(self, script: str) -> str:
() => document.querySelector('div[data-testid="chrome-extension-toast"]')
""",
)
except PlaywrightError as e:
except PlaywrightError:
pass

# try to close the extension banner
try:
await page.evaluate("""
await page.evaluate(
"""
document.querySelector('div[data-testid="chrome-extension-toast"]').querySelector('button').click()
""")
except PlaywrightError as e:
"""
)
except PlaywrightError:
pass

# select input / output language
Expand Down Expand Up @@ -177,10 +179,12 @@ async def __translate(self, script: str) -> str:

# Get the number of lines in the translated text field
try:
line_count = await page.evaluate("""
line_count = await page.evaluate(
"""
document.querySelector(
'd-textarea[aria-labelledby=translation-target-heading]').children[0].children.length
""")
"""
)
except PlaywrightError as e:
msg = "Unable to evaluate line count of the translation"
raise DeepLCLIPageLoadError(msg) from e
Expand All @@ -193,7 +197,7 @@ async def __translate(self, script: str) -> str:
await page.wait_for_function(
f"""
() => document.querySelector('d-textarea[aria-labelledby=translation-target-heading]')
?.children[0]?.children[{line}]?.innerText?.length > 0
?.children[0]?.children[{line}]?.innerText?.length > 0
&& !document.querySelector('d-textarea[aria-labelledby=translation-target-heading]')
?.children[0]?.children[{line}]?.innerText?.startsWith('[...]')
""",
Expand All @@ -203,10 +207,12 @@ async def __translate(self, script: str) -> str:
raise DeepLCLIPageLoadError(msg) from e

try:
translated_text = await page.evaluate(f"""
translated_text = await page.evaluate(
f"""
document.querySelector(
'd-textarea[aria-labelledby=translation-target-heading]').children[0].children[{line}].innerText
""")
"""
)
print(translated_text)
translated_lines.append(translated_text)
except PlaywrightError as e:
Expand Down

0 comments on commit 46f53c3

Please sign in to comment.