1
0
personal-data/personal_data/notification.py

52 lines
1.1 KiB
Python
Raw Normal View History

2024-06-02 21:16:11 +00:00
import enum
2024-06-02 21:14:19 +00:00
import logging
import requests
from frozendict import frozendict
from . import mailgun
logger = logging.getLogger(__name__)
2024-06-02 21:16:11 +00:00
2024-06-02 21:14:19 +00:00
class NotificationType(enum.Enum):
EMAIL = 1
LOUD_SOUND = 2
def send_email_notification(
session: requests.Session,
scraper_name: str,
latest_dict: frozendict,
) -> None:
body = ['A new update has occured for ', scraper_name, '\n']
for k, v in latest_dict.items():
body.append(f'{k}: {v}\n')
mailgun.send_email(session, f'Updated {scraper_name}', ''.join(body))
def play_loud_and_annoying_sound(
session: requests.Session,
scraper_name: str,
latest_dict: frozendict,
) -> None:
pass
2024-06-02 21:16:11 +00:00
2024-06-02 21:14:19 +00:00
NOTIFICATION_TYPE_TO_NOTIFIER = {
2024-06-02 21:16:11 +00:00
NotificationType.EMAIL: send_email_notification,
NotificationType.LOUD_SOUND: play_loud_and_annoying_sound,
2024-06-02 21:14:19 +00:00
}
def send_notifications(
session: requests.Session,
scraper_name: str,
latest_dict: frozendict,
notification_types: set[NotificationType],
) -> None:
for notification_type in notification_types:
2024-06-02 21:16:11 +00:00
NOTIFICATION_TYPE_TO_NOTIFIER[notification_type](
session, scraper_name, latest_dict,
)