-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_manager.py
More file actions
50 lines (41 loc) · 1.19 KB
/
Copy pathconfig_manager.py
File metadata and controls
50 lines (41 loc) · 1.19 KB
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
import json
import os
CONFIG_PATH = os.path.join(os.path.dirname(__file__), "config.json")
DEFAULTS = {
"city": "Oslo",
"timezone": "Europe/Oslo",
"api_key": "API-KEY-HERE",
"units": "metric",
"brightness": 100,
"clock_24h": False,
"night_mode": True,
"night_start": 23,
"night_end": 7,
"night_brightness": 15,
"theme": "dark",
"hotspot_ssid": "DeskClock",
"hotspot_password": "",
"hotspot_iface": "auto",
}
class ConfigManager:
def __init__(self):
self._data = dict(DEFAULTS)
self._load()
def _load(self):
if os.path.exists(CONFIG_PATH):
try:
with open(CONFIG_PATH) as f:
saved = json.load(f)
self._data.update(saved)
except Exception:
pass
def save(self):
with open(CONFIG_PATH, "w") as f:
json.dump(self._data, f, indent=2)
def get(self, key, default=None):
return self._data.get(key, default)
def set(self, key, value):
self._data[key] = value
def update(self, d):
self._data.update(d)
self.save()