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
