diff options
author | neodarz <neodarz@neodarz.net> | 2019-09-29 17:05:36 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-09-29 17:05:36 +0200 |
commit | d892b1c0b5a769ada9929907399dfde6a04d71c5 (patch) | |
tree | c738cdbb89ffde10181dc48adc76ece096914534 | |
parent | 987e1f00222a1fd9a566a7f7e096b586867e5e2a (diff) | |
download | pyshaarli-d892b1c0b5a769ada9929907399dfde6a04d71c5.tar.xz pyshaarli-d892b1c0b5a769ada9929907399dfde6a04d71c5.zip |
Add function to get an article
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | db.py | 23 |
2 files changed, 24 insertions, 1 deletions
@@ -12,7 +12,7 @@ Just simple, databaseless, static, shaarli like system link sharing. Fonctionalities: [ ] Flat file system management - [ ] Get an article + [X] Get an article [ ] Get all articles [ ] Get `n` articles from a range [ ] Add an article @@ -64,3 +64,26 @@ def import_bookmarks(bookmarks_file="bookmarks.html", force=False): else: logging.warning("File {} already exist!".format(final_file)) + +title = re.compile(r'^title: (.*)$') +published = re.compile(r'^published: (.*)$') +updated = re.compile(r'^updated: (.*)$') +link = re.compile(r'^link: (.*)$') +tags = re.compile(r'^tags: (.*)$') +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 |