This commit is contained in:
mcinj 2022-05-09 12:31:40 -04:00
parent 6241264147
commit 1d6d5da86e
2 changed files with 11 additions and 6 deletions

View file

@ -3,7 +3,7 @@ import urllib
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from tables import engine, TableNotification from tables import TableNotification
import log import log
logger = log.get_logger(__name__) logger = log.get_logger(__name__)
@ -46,10 +46,8 @@ class Notification:
response = conn.getresponse() response = conn.getresponse()
logger.debug(f"Pushover response code: {response.getcode()}") logger.debug(f"Pushover response code: {response.getcode()}")
if response.getcode() == 200: if response.getcode() == 200:
n = TableNotification(type=type_of_error, message=f"{message}", medium='pushover', success=True) success = True
else: else:
logger.error(f"Pushover notification failed. Code {response.getcode()}: {response.read().decode()}") logger.error(f"Pushover notification failed. Code {response.getcode()}: {response.read().decode()}")
n = TableNotification(type=type_of_error, message=f"{message}", medium='pushover', success=False) success = False
with Session(engine) as session: TableNotification.insert(type_of_error, f"{message}", 'pushover', success)
session.add(n)
session.commit()

View file

@ -22,6 +22,13 @@ class TableNotification(Base):
__mapper_args__ = {"eager_defaults": True} __mapper_args__ = {"eager_defaults": True}
@classmethod
def insert(cls, type_of_error, message, medium, success):
with Session(engine) as session:
n = TableNotification(type=type_of_error, message=message, medium=medium, success=success)
session.add(n)
session.commit()
@classmethod @classmethod
def get_won_notifications_today(cls): def get_won_notifications_today(cls):
with Session(engine) as session: with Session(engine) as session: