From 98cef3c4a540b3322e385f91f07079307f064523 Mon Sep 17 00:00:00 2001 From: Die4Ever Date: Sun, 14 Jan 2024 03:18:59 -0600 Subject: [PATCH] fix circular dep for logex --- libStreamDetective/libStreamDetective.py | 20 +------------------- libStreamDetective/notifiers.py | 9 ++++++--- libStreamDetective/util.py | 20 ++++++++++++++++++++ tests.py | 3 +++ 4 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 libStreamDetective/util.py diff --git a/libStreamDetective/libStreamDetective.py b/libStreamDetective/libStreamDetective.py index 4a2bdf3..77b47b9 100644 --- a/libStreamDetective/libStreamDetective.py +++ b/libStreamDetective/libStreamDetective.py @@ -18,6 +18,7 @@ from mastodon import Mastodon from libStreamDetective.config import validateConfig +from libStreamDetective.util import * from libStreamDetective.notifiers import CreateNotifier path = os.path.realpath(os.path.dirname(__file__)) @@ -674,25 +675,6 @@ def checkIsOnCooldown(self, stream, ProfileName) -> bool: - -def logex(sd: StreamDetective | None, e: BaseException, *args): - try: - estr = "".join(traceback.format_exception(BaseException, e, e.__traceback__)) - except: - estr = str(e) - - print("\nERROR: "+estr, *args, '\n') - - if sd: - argsStr = " ".join([*args]) - sd.genErrorMsgs("ERROR: "+estr+argsStr) - -def fromisoformat(iso): - # for compatibility with python 3.6 - if not iso: - return datetime(1970, 1, 1) - return datetime.strptime(iso, "%Y-%m-%dT%H:%M:%S.%f") - verbose = 1 debug = print trace = print diff --git a/libStreamDetective/notifiers.py b/libStreamDetective/notifiers.py index 33bbf8a..88c5c49 100644 --- a/libStreamDetective/notifiers.py +++ b/libStreamDetective/notifiers.py @@ -17,6 +17,9 @@ def __init__(self, config, parent): self.ErrorsSent = 0 + def sendError(self, errMsg): + raise RuntimeError(errMsg) + def handleSingleNotificationService(self, entry, newStreams): filteredStreams = self.parent.filterIgnoredStreams(self.ProfileName, newStreams) if self.dry_run: @@ -143,7 +146,7 @@ def buildDiscordMsgs(self, discordProfile, toSend, atUserId, titleOverride, cust try: gameArtUrl = self.parent.getGameBoxArt(gameName,144,192) #144x192 is the value used by Twitch if you open the image in a new tab except Exception as e: - logex(self,e) + logex(self.parent, e) url="https://twitch.tv/"+stream["user_login"] content += url + ' is playing ' + gameName @@ -230,7 +233,7 @@ def sendToot(self,profile,msg,raise_exc=True): debug(response) except Exception as e: if raise_exc: - logex(self, e, "Encountered an issue when attempting to toot: ", msg) + logex(self.parent, e, "Encountered an issue when attempting to toot: ", msg) @@ -277,7 +280,7 @@ def sendTweet(self, msg, raise_exc=True): debug(response) except Exception as e: if raise_exc: - logex(self, e, "Encountered an issue when attempting to tweet: ", msg) + logex(self.parent, e, "Encountered an issue when attempting to tweet: ", msg) diff --git a/libStreamDetective/util.py b/libStreamDetective/util.py new file mode 100644 index 0000000..9a12b76 --- /dev/null +++ b/libStreamDetective/util.py @@ -0,0 +1,20 @@ +import traceback +from datetime import datetime + +def logex(sd, e: BaseException, *args): + try: + estr = "".join(traceback.format_exception(BaseException, e, e.__traceback__)) + except: + estr = str(e) + + print("\nERROR: "+estr, *args, '\n') + + if sd: + argsStr = " ".join([*args]) + sd.genErrorMsgs("ERROR: "+estr+argsStr) + +def fromisoformat(iso): + # for compatibility with python 3.6 + if not iso: + return datetime(1970, 1, 1) + return datetime.strptime(iso, "%Y-%m-%dT%H:%M:%S.%f") diff --git a/tests.py b/tests.py index 4981492..16db17f 100644 --- a/tests.py +++ b/tests.py @@ -108,6 +108,9 @@ class TestNotifier(notifiers.Notifier): def handleMsgs(self, entry, filteredStreams): pass + def sendError(self, errMsg): + pass + @typechecked class TestStreamDetectiveBase(StreamDetective):