moved class Alert from cog_notificator.py to alert_notifiy.py

This commit is contained in:
yrrad8 2023-10-30 11:40:05 +02:00
parent 72fba9c20b
commit 110ab70349
2 changed files with 44 additions and 43 deletions

43
alert_notifiy.py Normal file
View File

@ -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'))

View File

@ -13,6 +13,7 @@ import db_access
import errlogging import errlogging
from db_access import * from db_access import *
from markdown import md from markdown import md
from alert_notifiy import Alert
load_dotenv() load_dotenv()
AUTHOR_ID = int(os.getenv('AUTHOR_ID')) AUTHOR_ID = int(os.getenv('AUTHOR_ID'))
@ -72,49 +73,6 @@ class AlertReqs:
return ret_dict 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: class AlertEmbed: