Add more functions to storage.py
- Add get_locations() - Add init_location() to create a new blank location - Add increment_amount() to increment the amount of one item - Remove set_brand_key() since it will be replaced by separate functions for each property you can set
This commit is contained in:
parent
09730acfcc
commit
d0abbef8d1
30
storage.py
30
storage.py
@ -28,10 +28,23 @@ def write_raw_json(writedict):
|
|||||||
print("Wrote dictionary as JSON to inventory.json")
|
print("Wrote dictionary as JSON to inventory.json")
|
||||||
|
|
||||||
|
|
||||||
|
def get_locations():
|
||||||
|
return list(load_raw_json().keys())
|
||||||
|
|
||||||
|
|
||||||
def get_items(location):
|
def get_items(location):
|
||||||
return load_raw_json()[location]
|
return load_raw_json()[location]
|
||||||
|
|
||||||
|
|
||||||
|
def init_location(location):
|
||||||
|
rawitems = load_raw_json()
|
||||||
|
if location not in rawitems.keys():
|
||||||
|
rawitems.update({location: {}})
|
||||||
|
write_raw_json(rawitems)
|
||||||
|
else:
|
||||||
|
raise AlreadyExistsError
|
||||||
|
|
||||||
|
|
||||||
def init_item(location, item):
|
def init_item(location, item):
|
||||||
rawitems = load_raw_json()
|
rawitems = load_raw_json()
|
||||||
if item not in rawitems[location].keys():
|
if item not in rawitems[location].keys():
|
||||||
@ -54,23 +67,16 @@ def init_brand(location, item, brand):
|
|||||||
raise AlreadyExistsError
|
raise AlreadyExistsError
|
||||||
|
|
||||||
|
|
||||||
def set_brand_key(location, item, brand, key, value):
|
def increment_amount(location, item, brand, amount):
|
||||||
rawitems = load_raw_json()
|
rawitems = load_raw_json()
|
||||||
if item not in rawitems[location].keys():
|
newamt = rawitems[location][item][brand][amount] + int(amount)
|
||||||
init_item(location, item)
|
rawitems[location][item][brand].update({"amount": newamt})
|
||||||
rawitems = load_raw_json()
|
|
||||||
|
|
||||||
if brand not in rawitems[location][item].keys():
|
|
||||||
init_brand(location, item, brand)
|
|
||||||
rawitems = load_raw_json()
|
|
||||||
|
|
||||||
rawitems[location][item][brand].update({key: value})
|
|
||||||
write_raw_json(rawitems)
|
write_raw_json(rawitems)
|
||||||
|
|
||||||
|
|
||||||
def rm_brand_key(location, item, brand, key):
|
def rm_brand_field(location, item, brand, field):
|
||||||
rawitems = load_raw_json()
|
rawitems = load_raw_json()
|
||||||
rawitems[location][item][brand].pop(key)
|
rawitems[location][item][brand].pop(field)
|
||||||
write_raw_json(rawitems)
|
write_raw_json(rawitems)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user