-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.py
65 lines (50 loc) · 1.35 KB
/
provider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import logging
import webbrowser
from abc import ABC, abstractmethod
import pyperclip
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
class Provider(ABC):
"""
Abstract class for translate providers
"""
def __init__(self, text: str) -> None:
self.text = text
self.url = self.get_url()
@abstractmethod
def get_url(self) -> str:
"""
Return url for translate service
"""
return "https://egorovegor.ru"
def open(self) -> None:
"""
Open default browser with new tab
"""
webbrowser.open_new_tab(self.url + self.text)
class Yandex(Provider):
def get_url(self) -> str:
return "https://translate.yandex.ru/?text="
class Google(Provider):
def get_url(self) -> str:
return "https://translate.google.com/?text="
class Promt(Provider):
def get_url(self) -> str:
return "https://www.translate.ru/?text="
def translate(name="Yandex") -> None:
"""
Proccesed clipboard to webbrowser
"""
clipboard = str(pyperclip.paste())
if name == "Yandex":
provider = Yandex
elif name == "Google":
provider = Google
elif name == "Promt":
provider = Promt
else:
provider = Yandex
p = provider(clipboard)
p.open()