-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nietoga/release-2
Release 2
- Loading branch information
Showing
16 changed files
with
242 additions
and
72 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import Type | ||
|
||
from mail import MailService | ||
from user_data import UserDataProvider | ||
from tray import Tray | ||
|
||
|
||
class ExternalServices: | ||
mail_service: MailService | ||
user_data_provider: UserDataProvider | ||
Tray: Type[Tray] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from external_services import ExternalServices | ||
|
||
|
||
def _configure_mail(): | ||
from .mail import mail_service | ||
|
||
ExternalServices.mail_service = mail_service | ||
|
||
|
||
def _configure_user_data(): | ||
from .user_data import user_data_provider | ||
|
||
ExternalServices.user_data_provider = user_data_provider | ||
|
||
|
||
def _configure_tray_class(): | ||
from .tray import TrayClass | ||
|
||
ExternalServices.Tray = TrayClass | ||
|
||
|
||
def configure(): | ||
_configure_mail() | ||
_configure_user_data() | ||
_configure_tray_class() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import config | ||
from mail.mailjet import MailJetService | ||
|
||
MAILJET_API_KEY = config.get("MAILJET_API_KEY") or "" | ||
MAILJET_API_SECRET = config.get("MAILJET_API_SECRET") or "" | ||
|
||
mail_service = MailJetService( | ||
api_key=MAILJET_API_KEY, | ||
api_secret=MAILJET_API_SECRET, | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from tray.pysg_tray import SgTray | ||
|
||
TrayClass = SgTray |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from user_data.pysg_provider import SgUserDataProvider | ||
|
||
user_data_provider = SgUserDataProvider("__lol_monitor__") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
|
||
CURRENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def get_absolute_path(local_path: str) -> str: | ||
return os.path.join(CURRENT_DIRECTORY, local_path) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
from .mailjet import send_mail | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class MailService(ABC): | ||
@abstractmethod | ||
def send_mail( | ||
self, | ||
email_from: str, | ||
email_to: str, | ||
subject: str, | ||
text_part: str, | ||
html_part: str | None = None, | ||
) -> bool: | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
from mailjet_rest import Client | ||
import config | ||
|
||
MAILJET_API_KEY = config.get("MAILJET_API_KEY") | ||
MAILJET_API_SECRET = config.get("MAILJET_API_SECRET") | ||
from mail import MailService | ||
|
||
mailjet = Client(auth=(MAILJET_API_KEY, MAILJET_API_SECRET), version="v3.1") | ||
|
||
class MailJetService(MailService): | ||
def __init__(self, api_key: str, api_secret: str, debug: bool = False) -> None: | ||
super().__init__() | ||
self._mailjet_client = Client(auth=(api_key, api_secret), version="v3.1") | ||
self._debug = debug | ||
|
||
def send_mail( | ||
email_from: str, | ||
email_to: str, | ||
subject: str, | ||
text_part: str, | ||
html_part: str | None = None, | ||
) -> bool: | ||
data = { | ||
"Messages": [ | ||
{ | ||
"From": {"Email": email_from}, | ||
"To": [{"Email": email_to}], | ||
"Subject": subject, | ||
"TextPart": text_part, | ||
"HTMLPart": html_part, | ||
} | ||
] | ||
} | ||
def send_mail( | ||
self, | ||
email_from: str, | ||
email_to: str, | ||
subject: str, | ||
text_part: str, | ||
html_part: str | None = None, | ||
) -> bool: | ||
data = { | ||
"Messages": [ | ||
{ | ||
"From": {"Email": email_from}, | ||
"To": [{"Email": email_to}], | ||
"Subject": subject, | ||
"TextPart": text_part, | ||
"HTMLPart": html_part, | ||
} | ||
] | ||
} | ||
|
||
response = mailjet.send.create(data=data) | ||
response = self._mailjet_client.send.create(data=data) | ||
|
||
print(response.status_code) | ||
print(response.json()) | ||
if self._debug: | ||
print(response.status_code) | ||
print(response.json()) | ||
|
||
return response.ok | ||
return response.ok |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Tray(ABC): | ||
DOUBLE_CLICK_EVENT = "__DOUBLE_CLICK__" | ||
|
||
def __init__(self, icon_path: str, menu_items: list[str]) -> None: | ||
self._icon_path = icon_path | ||
self._menu_items = menu_items | ||
self._visible = True | ||
self._closed = False | ||
self._listeners: dict[str,] = {} | ||
|
||
def set_visible(self, visible): | ||
self._visible = visible | ||
|
||
def is_visible(self): | ||
return self._visible | ||
|
||
def close(self): | ||
self._closed = True | ||
|
||
def is_closed(self): | ||
return self._closed | ||
|
||
def attach_listener(self, key, listener): | ||
self._listeners[key] = listener | ||
|
||
@abstractmethod | ||
def run(): | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import PySimpleGUIQt as sg | ||
|
||
from tray import Tray | ||
|
||
|
||
class SgTray(Tray): | ||
DOUBLE_CLICK_EVENT = sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED | ||
|
||
def __init__(self, icon_path: str, menu_items: list[str]) -> None: | ||
super().__init__(icon_path, menu_items) | ||
|
||
self._tray = sg.SystemTray( | ||
menu=["", self._menu_items], | ||
filename=self._icon_path, | ||
) | ||
|
||
def set_visible(self, visible): | ||
super().set_visible(visible) | ||
|
||
if self.is_visible(): | ||
self._tray.un_hide() | ||
else: | ||
self._tray.hide() | ||
|
||
def close(self): | ||
super().close() | ||
self._tray.close() | ||
|
||
def run(self): | ||
while not self.is_closed(): | ||
menu_item = self._tray.read(0) | ||
|
||
if menu_item in self._listeners: | ||
self._listeners[menu_item](self) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class UserDataProvider(ABC): | ||
@abstractmethod | ||
def set_user_data(self, key: str, value: str) -> None: | ||
pass | ||
|
||
@abstractmethod | ||
def get_user_data(self, key: str, default: str | None = None) -> str | None: | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import PySimpleGUIQt as sg | ||
|
||
from user_data import UserDataProvider | ||
|
||
|
||
class SgUserDataProvider(UserDataProvider): | ||
def __init__(self, settings_prefix: str = "") -> None: | ||
super().__init__() | ||
self._settings_prefix = settings_prefix | ||
|
||
def set_user_data(self, key: str, value: str) -> None: | ||
sg.user_settings_set_entry(self._settings_prefix + key, value) | ||
|
||
def get_user_data(self, key: str, default: str | None = None) -> str | None: | ||
return sg.user_settings_get_entry(self._settings_prefix + key, default) |
This file was deleted.
Oops, something went wrong.