diff options
Diffstat (limited to 'db.py')
-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): |