blob: 6a98ff4f6eeb383a1507a225467cecaad551cc13 (
plain)
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
|
import os
def ensure_path(path, default="0"):
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
if not os.path.exists(path):
with open(path, "w") as f:
f.write(default)
def add_one_to(path):
try:
with open(path, "r") as f:
total = int(f.read().strip())
except:
total = 0
total += 1
with open(path, "w") as f:
f.write(str(total))
def get_stats(path):
try:
with open(path) as f:
return int(f.read().strip())
except:
return 0
|