Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logic Improvement] Enable notifications for the first iteration of the scanner when the state is empty #548

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tgtg_scanner/scanner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import logging
import sys
from random import random
Expand Down Expand Up @@ -103,6 +104,15 @@ def _job(self) -> None:
except TgtgAPIError as err:
log.error(err)
items += self._get_favorites()

# if state is empty (first scanning iteration), initialize it with the current favorite items
# and set `items_available` property to 0.
# It allows to be able to receive notifications at start if some magic bags are already available.
if not self.state:
self.state = {item.item_id: copy.deepcopy(item) for item in items}
for item in self.state.values():
item.items_available = 0

for item in items:
self._check_item(item)

Expand Down