add the scripts for the meat consumption

This commit is contained in:
Andreas Zweili 2021-08-05 22:15:22 +02:00
parent d356cb6a41
commit f546a52405
3 changed files with 41 additions and 1 deletions

2
.gitignore vendored
View File

@ -208,4 +208,4 @@ flycheck_*.el
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
meat_consumption.json

18
enter_meat_consumption.py Normal file
View File

@ -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)

22
get_meat_consumption.py Normal file
View File

@ -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))