Last active
July 11, 2021 12:22
-
-
Save BishopKO/4f9bb2c8177dc28a964ce1f0ac0fd738 to your computer and use it in GitHub Desktop.
Simple online english-polish translator with automatic clipboard check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import re | |
from win10toast import ToastNotifier | |
import pyperclip | |
import time | |
def get_translation(word): | |
url = f'https://pl.pons.com/t%C5%82umaczenie/angielski-polski/{word}' | |
try: | |
response = requests.get(url) | |
except requests.exceptions.ConnectionError: | |
print('ConnectionError') | |
return ['...', '...'] | |
position = response.text.find('class="target"') | |
text = response.text[position:position + 100] | |
try: | |
result = re.findall(r'>(.*?)</a>', text)[0] | |
print(word, result) | |
return [word.upper(), result.upper()] | |
except IndexError: | |
return ['...', '...'] | |
if __name__ == '__main__': | |
toaster = ToastNotifier() | |
clipboard = pyperclip.paste() | |
while True: | |
if clipboard != pyperclip.paste(): | |
clipboard = pyperclip.paste() | |
english, polish = get_translation(clipboard) | |
toaster.show_toast(polish, english) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment