-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus.py
29 lines (26 loc) · 866 Bytes
/
status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import json
import os
import logging
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, Undefined, config
from datetime import datetime, timezone
@dataclass_json(undefined=Undefined.EXCLUDE)
@dataclass
class Status:
last_run:datetime = datetime.min.replace(tzinfo=timezone.utc)
@classmethod
def load(cls):
if os.path.exists("status.json"):
with open("status.json", 'r') as file:
try:
#j = json.load(file)
raw_json = file.read()
s = Status.from_json(raw_json)
return s
except Exception as exc:
logging.debug(exc)
return Status()
def save(self):
j = self.to_json(indent=2)
with open("status.json", 'w') as file:
file.write(j)