diff options
author | neodarz <neodarz@neodarz.net> | 2019-09-29 20:06:35 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-09-29 20:06:35 +0200 |
commit | 129c3a65c8310a3c21431ab8c6f8e1661fb7b3d2 (patch) | |
tree | 4a6269a90e9c0af0a60b1a3efb12481a725414fc | |
parent | edc11057e99ce2d69421f09fc5b6d94ca05b524c (diff) | |
download | pyshaarli-master.tar.xz pyshaarli-master.zip |
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | db.py | 38 |
2 files changed, 22 insertions, 18 deletions
@@ -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 @@ -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)) |