Skip to content

Commit

Permalink
updated how we track new drops in Rewards.py
Browse files Browse the repository at this point in the history
This approach dynamically updates latestProcessedDropTime based on the most recent drop it processes. It does not use a fixed time window but instead ensures that only drops newer than the most recently processed one are considered. As a result, it inherently accounts for any delays or gaps between checks.

Yudaotor#138 (comment)
  • Loading branch information
ReformedDoge authored Aug 14, 2024
1 parent a3429db commit 5df909c
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions EsportsHelper/Rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,38 @@
from EsportsHelper.Logger import log
from EsportsHelper.I18n import i18n
from EsportsHelper.Stats import stats
#remove later
import json

_ = i18n.getText
_log = i18n.getLog
#self.latestProcessedDropTime = 1723204948000 # Initialize with current time
class DropTracker:
def __init__(self):
log.info("New DropTracker instance initialized")

self.latestProcessedDropTime = int(datetime.now().timestamp() * 1e3)

def trackerCheckNewDrops(self, currentDropsList):
log.info("trackerCheckNewDrops Function Called")

# Sort drops by unlockedDateMillis in descending order
sorted_drops = sorted(currentDropsList, key=lambda drop: drop.get("unlockedDateMillis", 0), reverse=True)
newDropList = []

for drop in sorted_drops:
unlockedDateMillis = drop.get("unlockedDateMillis", -1)
# Only add drops that are newer than the initial latestProcessedDropTime
if unlockedDateMillis > self.latestProcessedDropTime:
log.info(f" unlockedDateMillis: {unlockedDateMillis}")
log.info(f" self.latestProcessedDropTime: {self.latestProcessedDropTime}")
newDropList.append(drop)

# Update latestProcessedDropTime if there are new drops
if newDropList:
self.latestProcessedDropTime = newDropList[0].get("unlockedDateMillis", self.latestProcessedDropTime)
log.info(f"Updated: self.latestProcessedDropTime: {self.latestProcessedDropTime}")
return newDropList


class Rewards:
Expand All @@ -32,6 +61,8 @@ def __init__(self, driver, youtube, twitch) -> None:
self.today = datetime.now().day
self.networkHandler = NetworkHandler(driver=driver)
self.wait = WebDriverWait(self.driver, 30)
self.drop_tracker = DropTracker()


def checkRewardsFlag(self, stream: str):
"""
Expand Down Expand Up @@ -532,6 +563,7 @@ def getRewardPage(self, newTab=False):
log.error(formatExc(format_exc()))

def checkNewDrops(self):
#log.info("checkNewDrops called")
"""
Check for new drops since the last check. If new drops are found, update relevant information and perform actions.
Expand All @@ -541,11 +573,11 @@ def checkNewDrops(self):
with open(f'./dropsHistory/{strftime("%Y%m%d-")}drops.txt', "a+"):
pass
stats.todayDrops = 0
newDropList = [drop for drop in stats.currentDropsList if (stats.lastDropCheckTime - 6000) <= drop.get("unlockedDateMillis", -1)]
newDropList = self.drop_tracker.trackerCheckNewDrops(stats.currentDropsList)
# newDropList = [drop for drop in stats.currentDropsList if drop.get("cappedDrop", False)]
if len(newDropList) > 0:
if newDropList:
newDrops = parseDropList(newDropList)

#log.info(f"Logging newDropList array: {json.dumps(newDropList, indent=2)}")
for drop in newDrops:
cappedInfo = " "
if str(drop.numberOfFansUnlocked) != "0" and drop.capped:
Expand Down Expand Up @@ -577,4 +609,3 @@ def checkNewDrops(self):
log.error(formatExc(format_exc()))
else:
pass
stats.lastDropCheckTime = int(datetime.now().timestamp() * 1e3)

0 comments on commit 5df909c

Please sign in to comment.