-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstats.py
More file actions
39 lines (25 loc) · 755 Bytes
/
stats.py
File metadata and controls
39 lines (25 loc) · 755 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
39
import json
import traceback
global records
stats = {}
def new_report():
if len(stats) == 0:
raise RuntimeError('not loaded')
# TODO
pass
def save_and_reset():
global stats
if len(stats) == 0:
raise RuntimeError('not loaded')
with open('../last_stats_record.json', 'w', encoding='utf8') as fstream:
json.dump(stats, fstream, ensure_ascii=False)
stats = {}
def load():
global stats
with open('../last_stats_record.json', 'r', encoding='utf8') as fstream:
try:
stats_json = fstream.read()
stats = json.loads(stats_json)
except json.decoder.JSONDecodeError:
print('Failed to read stats file:')
traceback.print_exc()