Skip to content

Commit 5240088

Browse files
committed
Logic improvement: first scanner iteration: enable notifications as well
1 parent c70295a commit 5240088

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tgtg_scanner/scanner.py

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from random import random
44
from time import sleep
55
from typing import Dict, List, NoReturn, Union
6+
import copy
67

78
from progress.spinner import Spinner
89

@@ -104,6 +105,14 @@ def _job(self) -> None:
104105
except TgtgAPIError as err:
105106
log.error(err)
106107
items += self._get_favorites()
108+
109+
# if state is empty (first scanning iteration), initialize it with the current favorite items and set `items_available` property to 0.
110+
# It allows to be able to receive notifications at start if some magic bags are already available.
111+
if not self.state:
112+
self.state = {item.item_id: copy.deepcopy(item) for item in items}
113+
for item in self.state.values():
114+
item.items_available = 0
115+
107116
for item in items:
108117
self._check_item(item)
109118

0 commit comments

Comments
 (0)