diff options
Diffstat (limited to 'statistics.py')
| -rw-r--r-- | statistics.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/statistics.py b/statistics.py new file mode 100644 index 0000000..6a98ff4 --- /dev/null +++ b/statistics.py @@ -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 |