media-sucker/src/state.py

26 lines
471 B
Python

#! /usr/bin/python3
import json
class State(dict):
def __init__(self, path):
super().__init__()
self.path = path
self.read()
def read(self):
try:
f = open(self.path)
except FileNotFoundError:
return
obj = json.load(f)
f.close()
for k in obj:
self[k] = obj[k]
def write(self):
f = open(self.path, "w")
json.dump(self, f)
f.close()