From 110ab70349b59603a6cadfaecc3b576542335122 Mon Sep 17 00:00:00 2001 From: yrrad8 Date: Mon, 30 Oct 2023 11:40:05 +0200 Subject: [PATCH] moved class Alert from cog_notificator.py to alert_notifiy.py --- alert_notifiy.py | 43 +++++++++++++++++++++++++++++++++++++++++++ cog_notificator.py | 44 +------------------------------------------- 2 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 alert_notifiy.py diff --git a/alert_notifiy.py b/alert_notifiy.py new file mode 100644 index 0000000..760f4cd --- /dev/null +++ b/alert_notifiy.py @@ -0,0 +1,43 @@ +class Alert: + """ + Represents an HFC Alert + """ + def __init__(self, id: int, cat: int, title: str, districts: list[str], desc: str): + """ + Init an Alert instance + :param id: Alert ID + :param cat: Alert category + :param title: Alert title + :param districts: districts the alert is running for + :param desc: Alert description/extra info + """ + self.id = id + self.category = cat + self.title = title + self.districts = districts + self.description = desc + + @classmethod + def from_dict(cls, data: dict): + """ + Return a new Alert instance from an Alert-formatted dict (matching HFC alert requests) + + Dict format: + + { + "id": int, + "cat": int, + "title": str, + "data": list[str], + "desc": str + } + + :param data: A dict of matching format + + :return: The new Alert instance + """ + return cls(int(data.get('id', '0')), + int(data.get('cat', '0')), + data.get('title'), + data.get('data'), + data.get('desc')) diff --git a/cog_notificator.py b/cog_notificator.py index 6a5762a..aebd9c4 100644 --- a/cog_notificator.py +++ b/cog_notificator.py @@ -13,6 +13,7 @@ import db_access import errlogging from db_access import * from markdown import md +from alert_notifiy import Alert load_dotenv() AUTHOR_ID = int(os.getenv('AUTHOR_ID')) @@ -72,49 +73,6 @@ class AlertReqs: return ret_dict -class Alert: - """ - Represents an HFC Alert - """ - def __init__(self, id: int, cat: int, title: str, districts: list[str], desc: str): - """ - Init an Alert instance - :param id: Alert ID - :param cat: Alert category - :param title: Alert title - :param districts: districts the alert is running for - :param desc: Alert description/extra info - """ - self.id = id - self.category = cat - self.title = title - self.districts = districts - self.description = desc - - @classmethod - def from_dict(cls, data: dict): - """ - Return a new Alert instance from an Alert-formatted dict (matching HFC alert requests) - - Dict format: - - { - "id": int, - "cat": int, - "title": str, - "data": list[str], - "desc": str - } - - :param data: A dict of matching format - - :return: The new Alert instance - """ - return cls(int(data.get('id', '0')), - int(data.get('cat', '0')), - data.get('title'), - data.get('data'), - data.get('desc')) class AlertEmbed: