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: