aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/db.py b/db.py
index 40de215..3fc7c6f 100644
--- a/db.py
+++ b/db.py
@@ -74,19 +74,23 @@ archive = re.compile(r'^archive: (.*)$')
private = re.compile(r'^private: (.*)$')
comment = re.compile(r'---[\s\S]*?---[\s\S]([\s\S]*)',)
def bookmark(path):
- bookmark = {}
- with open(path, 'r', encoding="utf-8") as f:
- lines = f.readlines()
- bookmark["path"] = path
- bookmark["title"] = [m.group(1) for l in lines for m in [title.search(l)] if m][0]
- bookmark["published"] = [m.group(1) for l in lines for m in [published.search(l)] if m][0]
- bookmark["updated"] = [m.group(1) for l in lines for m in [updated.search(l)] if m][0]
- bookmark["link"] = [m.group(1) for l in lines for m in [link.search(l)] if m][0]
- bookmark["tags"] = [m.group(1) for l in lines for m in [tags.search(l)] if m][0]
- bookmark["archive"] = [m.group(1) for l in lines for m in [archive.search(l)] if m][0]
- bookmark["private"] = [m.group(1) for l in lines for m in [private.search(l)] if m][0]
- bookmark["comment"] = [m.group(1) for m in [comment.search("".join(lines))] if m][0]
- return bookmark
+ path = Path(path)
+ try:
+ bookmark = {}
+ with open(path, 'r', encoding="utf-8") as f:
+ lines = f.readlines()
+ bookmark["path"] = path
+ bookmark["title"] = [m.group(1) for l in lines for m in [title.search(l)] if m][0]
+ bookmark["published"] = [m.group(1) for l in lines for m in [published.search(l)] if m][0]
+ bookmark["updated"] = [m.group(1) for l in lines for m in [updated.search(l)] if m][0]
+ bookmark["link"] = [m.group(1) for l in lines for m in [link.search(l)] if m][0]
+ bookmark["tags"] = [m.group(1) for l in lines for m in [tags.search(l)] if m][0]
+ bookmark["archive"] = [m.group(1) for l in lines for m in [archive.search(l)] if m][0]
+ bookmark["private"] = [m.group(1) for l in lines for m in [private.search(l)] if m][0]
+ bookmark["comment"] = [m.group(1) for m in [comment.search("".join(lines))] if m][0]
+ return bookmark
+ except FileNotFoundError:
+ logging.warning("{} doesn't exist!".format(path.name))
def bookmarks(path):