-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
35 lines (26 loc) · 884 Bytes
/
settings.py
File metadata and controls
35 lines (26 loc) · 884 Bytes
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
import json
import os
settings_file = os.path.expanduser("~/.cli_inbox_settings.json")
default_settings = {
"emails_per_page": 20,
"download_folder": os.path.join(os.path.expanduser("~"), "Downloads"),
"signature": "",
"auto_mark_read": True,
"default_label": "INBOX",
"aliases": {}
}
def load_settings():
if not os.path.exists(settings_file):
save_settings(default_settings)
with open(settings_file, "r") as file:
return dict(json.load(file))
with open(settings_file, "r") as file:
loaded = json.load(file)
merged = dict(default_settings)
merged.update(loaded)
if not isinstance(merged.get("aliases"), dict):
merged["aliases"] = {}
return merged
def save_settings(settings):
with open(settings_file, "w") as file:
json.dump(settings, file, indent=4)