-# class Database:
-# data_default = {
-# "timestamp_year": 0,
-# "timestamp_month": 0,
-# "timestamp_week": 0,
-# "year_income": 0,
-# "month_income": 0,
-# "week_income": 0,
-# "workday_hourly_rate_1": 10,
-# "workday_minutes_worked_1": 0,
-# "workday_hourly_rate_2": 25,
-# "workday_minutes_worked_2": 0,
-# "workday_hourly_rate_3": 50,
-# "workday_minutes_worked_3": 0,
-# "year_goal": 20000,
-# "workdays_per_month": 16
-# }
-# def __init__(self):
-# if os.path.exists(db_file):
-# with open(db_file, "r") as f:
-# return json.load(f)
-# else:
-# return db_default
+class IncomeDB(PlomDB):
+
+ def __init__(self):
+ # defaults
+ self.timestamp_year = 0,
+ self.timestamp_month = 0,
+ self.timestamp_week = 0,
+ self.year_income = 0,
+ self.month_income = 0,
+ self.week_income = 0,
+ self.workday_hourly_rate_1 = 10,
+ self.workday_hourly_rate_2 = 25,
+ self.workday_hourly_rate_3 = 50,
+ self.workday_minutes_worked_1 = 0,
+ self.workday_minutes_worked_2 = 0,
+ self.workday_minutes_worked_3 = 0,
+ self.year_goal = 20000,
+ self.workdays_per_month = 16
+ super().__init__(db_path)
+
+ def read_db_file(self, f):
+ d = json.load(f)
+ for k, v in d.items():
+ if not hasattr(self, k):
+ raise PlomException("bad key in db: " + k)
+ setattr(self, k, v)
+
+ def to_dict(self):
+ keys = [k for k in dir(self) if (not k.startswith('_')) and (not callable(getattr(self, k)))]
+ d = {}
+ for k in keys:
+ d[k] = getattr(self, k)
+ return d
+
+ def write_db(self):
+ self.write_text_to_db(json.dumps(self.to_dict()))
+