forked from SthPhoenix/PIK_monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
38 lines (29 loc) · 776 Bytes
/
helpers.py
File metadata and controls
38 lines (29 loc) · 776 Bytes
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
import os
import json
import hashlib
from flatten_dict import flatten
def hash_vals(data):
keys = sorted([e for e in data])
hash = hashlib.sha512()
for key in keys:
hash.update(str(data[key]).encode())
digest = hash.hexdigest()
return digest
def dump_data(data, path):
with open(path, mode='w') as fl:
json.dump(data, fl, indent=2, ensure_ascii=False)
fl.close()
def load_data(path):
try:
with open(path, mode='r') as fl:
data = json.load(fl)
return data
except:
return {}
def compare(a, b):
keys = set(a.keys()).union(set(b.keys()))
diff = []
for key in keys:
if a.get(key, 'null') != b.get(key, 'null'):
diff.append(key)
return diff