import os import secrets def get_secret(fn=".secret"): if os.path.exists(fn): res = read(fn) else: res = secrets.token_hex(32) write(res, fn) return res.strip() def read(fn): with open(fn) as f: return f.read() def write(s, fn): with open(fn, "w") as f: f.write(s)