Skip to content

Commit

Permalink
fix circular dep for logex
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Jan 14, 2024
1 parent cb499e9 commit 98cef3c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
20 changes: 1 addition & 19 deletions libStreamDetective/libStreamDetective.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions libStreamDetective/notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)



Expand Down Expand Up @@ -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)



Expand Down
20 changes: 20 additions & 0 deletions libStreamDetective/util.py
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 3 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class TestNotifier(notifiers.Notifier):
def handleMsgs(self, entry, filteredStreams):
pass

def sendError(self, errMsg):
pass


@typechecked
class TestStreamDetectiveBase(StreamDetective):
Expand Down

0 comments on commit 98cef3c

Please sign in to comment.