From 970f944529fcf560710feedbaf194f963f2e4d9b Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 29 Sep 2019 19:16:37 +0200 Subject: Warning if file doesn't exist when asking to see an article --- db.py | 30 +++++++++++++++++------------- 1 file 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): -- cgit v1.2.1