-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.py
36 lines (28 loc) · 1.19 KB
/
main.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
import json
with open('clone.json', 'r') as fh:
now = json.load(fh)
with open('clone_before.json', 'r') as fh:
before = json.load(fh)
timestamps = {before['clones'][i]['timestamp']: i for i in range(len(before['clones']))}
latest = dict(before)
for i in range(len(now['clones'])):
timestamp = now['clones'][i]['timestamp']
if timestamp in timestamps:
latest['clones'][timestamps[timestamp]] = now['clones'][i]
else:
latest['clones'].append(now['clones'][i])
latest['count'] = sum(map(lambda x: int(x['count']), latest['clones']))
latest['uniques'] = sum(map(lambda x: int(x['uniques']), latest['clones']))
if len(timestamps) > 100:
remove_this = []
clones = latest['clones']
for i in range(len(timestamps) - 35):
clones[i]['timestamp'] = clones[i]['timestamp'][:7]
if clones[i]['timestamp'] == clones[i+1]['timestamp'][:7]:
clones[i+1]['count'] += clones[i]['count']
clones[i+1]['uniques'] += clones[i]['uniques']
remove_this.append(clones[i])
for item in remove_this:
clones.remove(item)
with open('clone.json', 'w', encoding='utf-8') as fh:
json.dump(latest, fh, ensure_ascii=False, indent=4)