-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_changes.py
62 lines (41 loc) · 1.49 KB
/
test_changes.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
52
53
54
55
56
57
58
59
60
61
62
import json
import requests
from requests import HTTPError
def load_data():
with open('/tmp/jedeschule-changes.json') as infile:
return json.load(infile)
def fetch_data(school_id):
response = requests.get(f"https://jedeschule.codefor.de/schools/{school_id}")
response.raise_for_status()
return response.json()
def sort_dict(data):
return {key: value for key, value in sorted(data.items(), key=lambda k: k[0])}
def get_clean_item(data):
return set({key: value for key, value in data.items() if value is not None and key != "update_timestamp"})
def compare_schools(new_school, old_school):
new_school = sort_dict(new_school)
old_school = sort_dict(old_school)
new_values = get_clean_item(new_school)
old_values = get_clean_item(old_school)
differences = new_values ^ old_values
if not differences:
print(' no changes \n')
return
print(f"Difference: {differences}")
print(f"Old: {old_school}")
print(f"New: {new_school}")
def main():
data = load_data()
for school in data[:10]:
school_id = school.get('info').get('id')
print()
print('#'*10, f'Comparing {school_id}')
upstream_data = {}
try:
upstream_data = fetch_data(school_id)
except HTTPError as e:
print(f"WARN: Could not fetch old data for school-id {school_id}: {e}")
print()
compare_schools(school.get('info'), upstream_data)
if __name__ == "__main__":
main()