Skip to content

Instantly share code, notes, and snippets.

@curita
Last active June 29, 2017 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curita/690b39cbcddd9ac918de4087e7870327 to your computer and use it in GitHub Desktop.
Save curita/690b39cbcddd9ac918de4087e7870327 to your computer and use it in GitHub Desktop.
Calculate total amount of products in middle shelves from [REDACTED] SH job
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