forked from dthirumalaibe/globomantics_crm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase2.py
51 lines (43 loc) · 1.61 KB
/
database2.py
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
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""
Author: Nick Russo
Purpose: A simple Flask web app that demonstrates the Model View Controller
(MVC) pattern in a meaningful and somewhat realistic way.
"""
class Database:
"""
asdasd
Represent the interface to the data (model). Can read from a
dd simple file such as JSON, YAML, or XML. Uses JSON by default.
"""
def __init__(self, path):
"""
Constructor to initialize the data attribute as
a dictionary where the account number is the key and
the value is another dictionary with keys "paid" and "due".
"""
# Open the specified database file for reading and perform loading
with open(path, "r") as handle:
import json
self.data = json.load(handle)
# ALTERNATIVE IMPLEMENTATIONS: Using YAML or XML to load data
# import yaml
# self.data = yaml.safe_load(handle)
# import xmltodict
# self.data = xmltodict.parse(handle.read())["root"]
# print(self.data)
def balance(self, acct_id):
"""
Determines the customer balance by finding the difference between
can provide methods to help interface with the data; it is not
limited to only storing data. A positive number means the customer
a credit with us.
"""
acct = self.data.get(acct_id)
# I ADDED SOME WORDS
if acct:
bal = float(acct["due"]) - float(acct["paid"])
return f"{bal:.2f} ISK"
# return f"$ {bal:.2f}"
# return int(acct["due"]) - int(acct["paid"])
return None