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 --- db.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'db.py') 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