Last active
June 29, 2017 10:07
-
-
Save curita/690b39cbcddd9ac918de4087e7870327 to your computer and use it in GitHub Desktop.
Calculate total amount of products in middle shelves from [REDACTED] SH job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hubstorage import HubstorageClient | |
hs = HubstorageClient('<API_KEY>') | |
class Shelf(): | |
def __init__(self): | |
self.children = defaultdict(Shelf) | |
self.products = 0 | |
def __iter__(self): | |
for child in self.children.values(): | |
for item in child: | |
yield item | |
yield self.products | |
category_tree = Shelf() | |
for item in hs.get_job('3784/5/386').items.iter_values(): | |
top = category_tree | |
for shelf in item['category'].split(' > '): | |
top.products = min(top.products + 1, 24 * 400) | |
top = top.children[shelf] | |
sum(category_tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment