From 129c3a65c8310a3c21431ab8c6f8e1661fb7b3d2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 29 Sep 2019 20:06:35 +0200 Subject: Add function for add an article --- README.md | 2 +- db.py | 38 +++++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d34e6bf..dc049bb 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Fonctionalities: [X] Get an article [X] Get all articles [ ] Get `n` articles from a range - [ ] Add an article + [X] Add an article [X] Delete an article [ ] Edit an article [X] Import from shaarli 0.11 diff --git a/db.py b/db.py index cb280d8..9b1c66f 100644 --- a/db.py +++ b/db.py @@ -46,23 +46,7 @@ def import_bookmarks(bookmarks_file="bookmarks.html", force=False): if title != "": - final_file = Path("links/"+slugify(title, max_length=120)) - if not final_file.is_file() or force: - logging.info("Import file {}".format(final_file)) - with open(final_file, "w", encoding="utf-8") as link: - file_content = "---\n" - file_content += "title: {}\n".format(title) - file_content += "published: {}\n".format(add_date) - file_content += "updated: {}\n".format(add_date) - file_content += "link: {}\n".format(href) - file_content += "tags: {}\n".format(tags) - file_content += "archive: {}\n".format(archive) - file_content += "private: {}\n".format(private) - file_content += "---\n" - file_content += "{}".format(data) - link.write(file_content) - else: - logging.warning("File {} already exist!".format(final_file)) + add(title, add_date, add_date, href, tags, archive, private, data, force) title = re.compile(r'^title: (.*)$') @@ -108,3 +92,23 @@ def remove(path): logging.info("{} removed".format(path.name)) except FileNotFoundError: logging.warning("{} doesn't exist!".format(path.name)) + + +def add(title, published="", updated="", link="", tags="", archive="", private="", comment="", force=False): + final_file = Path("links/"+slugify(title, max_length=120)) + if not final_file.is_file() or force: + logging.info("Add file {}".format(final_file)) + with open(final_file, "w", encoding="utf-8") as bookmark: + file_content = "---\n" + file_content += "title: {}\n".format(title) + file_content += "published: {}\n".format(published) + file_content += "updated: {}\n".format(updated) + file_content += "link: {}\n".format(link) + file_content += "tags: {}\n".format(tags) + file_content += "archive: {}\n".format(archive) + file_content += "private: {}\n".format(private) + file_content += "---\n" + file_content += "{}".format(comment) + bookmark.write(file_content) + else: + logging.warning("File {} already exist!".format(final_file)) -- cgit v1.2.1