Skip to content

Instantly share code, notes, and snippets.

@afroisalreadyinu
Last active August 25, 2016 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save afroisalreadyinu/63d7f839d93555d9e94a9b409319ec89 to your computer and use it in GitHub Desktop.
Save afroisalreadyinu/63d7f839d93555d9e94a9b409319ec89 to your computer and use it in GitHub Desktop.
def build_book_inventory(book_ids, shops):
shop_labels = [shop['label'] for shop in shops]
book_list = Persistency.books_table.read(
shops=shop_labels,
books=book_ids)
inventory = {}
for book_item in book_list:
shop_label = book_item['shop_label']
cell_label = book_item['cell_label']
book_id = book_item['book_id']
count = book_item['count']
if shop_label not in inventory:
inventory[shop_label] = {}
if cell_label not in inventory[shop_label]:
inventory[shop_label][cell_label] = {}
inventory[shop_label][cell_label][book_id] = count
return inventory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment