forked from yjqiang/yj_ebook_reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_loader.py
38 lines (31 loc) · 1.23 KB
/
config_loader.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
import toml
class ConfigLoader():
def __init__(self):
self.file_conf = 'conf/parser.toml'
self.dict_conf = self.read_conf()
self.file_bookmark = 'conf/bookmarks.toml'
self.dict_bookmark = self.read_bookmark()
# print(self.dict_conf)
def read_conf(self):
with open(self.file_conf, encoding="utf-8") as f:
dict_conf = toml.load(f)
return dict_conf
def read_bookmark(self):
with open(self.file_bookmark, encoding="utf-8") as f:
dict_bookmark = toml.load(f)
if not dict_bookmark:
dict_bookmark = {'bookmarks': []}
return dict_bookmark
def check_bookmark(self, new_bm):
if new_bm is None:
return True
for bm in self.dict_bookmark['bookmarks']:
if bm['i'] == new_bm['i'] and \
bm['j'] == new_bm['j'] and \
bm['url'] == new_bm['url']:
return True
return False
def refresh_file(self, bmview):
self.dict_bookmark['bookmarks'] = bmview.items
with open(self.file_bookmark, 'w', encoding="utf-8") as f:
toml.dump(self.dict_bookmark, f)