-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.py
53 lines (40 loc) · 1.39 KB
/
state.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class IsKDPOpenState:
def _get_initial_state(self):
return {
"status": "Nieznany",
"message": "Z jakiegoś powodu nie możemy określić statusu otwarcia KDP",
"latest_online_status": False,
"latest_check_time": "Nigdy",
"latest_update_time": "jakiegoś czasu",
"visitors_today": {"day": 0, "visitors": {}},
"latest_api_response": {},
"admin_sessions": [],
"crew_information": {}
}
def _read_state(self):
return self.state
def _write_state(self, state):
if not hasattr(self, "state"):
self.state = {}
for s in state.keys():
self.state[s] = state[s]
def get_state(self):
state = self._read_state()
if not state:
state = self._get_initial_state()
self._write_state(state)
return state
def set_state(self, state):
return self._write_state(state)
def __init__(self):
self.set_state({})
class IsKDPOpenStateJSONFile(IsKDPOpenState):
def __init__(self, filepath):
super(IsKDPOpenStateJSONFile).__init__()
self.filepath = filepath
def _read_state(self):
return self.state
def _write_state(self, state):
for s in state.keys():
self.state[s] = state[s]
state = IsKDPOpenState()