Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Oct 9, 2024
1 parent 3a1317e commit 8ee6542
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
6 changes: 5 additions & 1 deletion libStreamDetective/libStreamDetective.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,17 @@ def genErrorMsgs(self,errMsg):
def filterIgnoredStreams(self,profileName,newStreams):
IgnoreStreams = self.config.get('IgnoreStreams', [])
toSend = []
onCooldown = []
for stream in newStreams:
if stream["user_login"].lower() in IgnoreStreams:
debug(stream["user_login"], 'is in IgnoreStreams')
continue
if self.checkIsOnCooldown(stream, profileName):
onCooldown.append(stream["user_login"])
continue
toSend.append(stream)
if onCooldown:
print('On cooldown for', profileName, ':', onCooldown)
return toSend


Expand All @@ -219,7 +223,7 @@ def checkIsOnCooldown(self, stream, ProfileName) -> bool:
res = db.fetchone('SELECT * FROM cooldowns WHERE streamer=? AND notifier=? AND last>?', (user, ProfileName, now-CooldownSeconds))
db.exec('INSERT INTO cooldowns(streamer, notifier, last) VALUES(?,?,?) ON CONFLICT DO UPDATE SET last=excluded.last', (user, ProfileName, now))
if res:
print(user, 'is on cooldown for', ProfileName)
debug(user, 'is on cooldown for', ProfileName)
return True
return False

8 changes: 3 additions & 5 deletions libStreamDetective/notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ def sendError(self, errMsg):
def handleSingleNotificationService(self, notifierData, entry, newStreams):
if self.dry_run:
print('\nhandleSingleNotificationService dry-run')
print('service:')
print(self)
print('entry:')
print(entry)
print(" New Streams: "+str([stream['user_login'] for stream in newStreams]), '\n')
print('service:', self.ProfileName)
print(' entry:', entry)
print(" New Streams: ", [stream['user_login'] for stream in newStreams], '\n')
return

if notifierData and notifierData.get('chance', 100) < random.randint(1, 100):
Expand Down
2 changes: 1 addition & 1 deletion libStreamDetective/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def HandleFilters(self, search, allStreams):

# All stream info now retrieved
if newStreams:
print(" Matched Streams: "+str([stream['user_login'] for stream in newStreams]))
print(" Matched Streams:", [stream['user_login'] for stream in newStreams])
self.genNotifications(newStreams, search)

debug("\n\n")
Expand Down
3 changes: 2 additions & 1 deletion libStreamDetective/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def FetchAllStreams(self, gameNames:set, streamers:set):
gameName = stream["game_name"].lower()
if gameName not in fetchedGames:
fetchedGames[gameName] = []
fetchedGames[gameName].append(stream)
if stream not in fetchedGames[gameName]:
fetchedGames[gameName].append(stream)
user = stream["user_login"].lower()
fetchedStreamers[user] = stream

Expand Down

0 comments on commit 8ee6542

Please sign in to comment.