From 976e397c1fdce8b83869028c7e744e454d24faf7 Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Sat, 4 Sep 2021 09:14:37 +1000 Subject: [PATCH] updates --- python/introduction/part-3.json/src/app.py | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/python/introduction/part-3.json/src/app.py b/python/introduction/part-3.json/src/app.py index c070912..351c3a9 100644 --- a/python/introduction/part-3.json/src/app.py +++ b/python/introduction/part-3.json/src/app.py @@ -14,16 +14,20 @@ def getCustomers(): if os.path.isfile("customers.json"): with open('customers.json', newline='') as customerFile: data = customerFile.read() - customers = json.loads(data) + customers = json.loads(data) return customers else: return {} -def updateCustomers(customer): - with open('customers.json', 'w', newline='') as customerFile: - customerJSON = json.dumps(customer) - customerFile.write(customerJSON) +def getCustomer(customerID): + customer = getCustomers() + return customer[customerID] +def updateCustomers(customers): + with open('customers.json', 'w', newline='') as customerFile: + customerJSON = json.dumps(customers) + customerFile.write(customerJSON) + customers = { "a": Customer("a","James", "Baker"), "b": Customer("b", "Jonathan", "D"), @@ -35,16 +39,15 @@ customers = { "h" : Customer("h", "Marcel", "Dempers") } - customerDict = {} + for id in customers: customerDict[id] = customers[id].__dict__ + updateCustomers(customerDict) customers = getCustomers() +customers["i"] = Customer("i", "Bob", "Smith").__dict__ -customers["i"] = Customer("i", "Marcel", "Dempers").__dict__ -updateCustomers(customers) - -print(customers) +updateCustomers(customers) \ No newline at end of file