-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIMS_ServerSide.py
More file actions
44 lines (32 loc) · 1.11 KB
/
IMS_ServerSide.py
File metadata and controls
44 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
no_of_Products = int(input("Enter the Number of Products to save: "))
prod = {}
def get_product_details(n):
for j in range(n):
print("\n Enter the Product details :\n ")
product_id = int(input("ID:"))
product_name = input("Name:")
product_price = float(input("Price:"))
product_quantity = int(input("Quantity:"))
prod[product_id] = {"name": product_name, "price": product_price, "quantity": product_quantity}
def write_product():
# first Time use
"""jFile = open("inventory.json", 'w')
jFile.write(json.dumps(prod))
jFile.close()"""
# continued use
jFile = open("inventory.json", 'r+')
old_prod = json.load(jFile)
# print(old_prod)
for p in prod:
if str(p) not in old_prod:
old_prod[p] = prod[p]
else:
prod[p]["quantity"] += old_prod[str(p)]["quantity"]
old_prod.update({str(p): prod[p]})
jFile.seek(0)
json.dump(old_prod, jFile, indent=4)
jFile.close()
get_product_details(no_of_Products)
write_product()
print("\n The Products are Added to inventory!")