added global statistics
This commit is contained in:
1 parent
f9207e1f99
commit
8861fbbb4b
5 files changed
+91
No files matched your search
@@ -0,0 +1,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
|
||||
Reference in new issue
Block a user