diff options
author | neodarz <neodarz@neodarz.net> | 2019-09-29 19:16:37 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-09-29 19:16:37 +0200 |
commit | 970f944529fcf560710feedbaf194f963f2e4d9b (patch) | |
tree | b1123660fa3eb19435fc88e25fb7ffa446c97138 | |
parent | 7f9959d9577cfd372349f1a675e804c84c1ff82d (diff) | |
download | pyshaarli-970f944529fcf560710feedbaf194f963f2e4d9b.tar.xz pyshaarli-970f944529fcf560710feedbaf194f963f2e4d9b.zip |
Warning if file doesn't exist when asking to see an article
-rw-r--r-- | db.py | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -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): |