add the scripts for the meat consumption
This commit is contained in:
parent
d356cb6a41
commit
f546a52405
|
@ -208,4 +208,4 @@ flycheck_*.el
|
|||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
meat_consumption.json
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import json
|
||||
import sys
|
||||
import get_meat_consumption as meat
|
||||
|
||||
filename = 'meat_consumption.json'
|
||||
|
||||
def write_data(data):
|
||||
try:
|
||||
input_dict = json.loads(sys.argv[1])
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return
|
||||
data.update(input_dict)
|
||||
with open(filename, 'w') as f:
|
||||
json.dump(data, f)
|
||||
|
||||
data = meat.get_data()
|
||||
write_data(data)
|
|
@ -0,0 +1,22 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
|
||||
filename = 'meat_consumption.json'
|
||||
|
||||
def get_data():
|
||||
try:
|
||||
with open(filename) as f:
|
||||
return json.load(f)
|
||||
except FileNotFoundError:
|
||||
open(filename, 'w')
|
||||
return json.loads("{}")
|
||||
|
||||
|
||||
def calculate_sum(data):
|
||||
return round(sum(data.values()), 4)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
data = get_data()
|
||||
print(calculate_sum(data))
|
Loading…
Reference in New Issue