aboutsummaryrefslogtreecommitdiff
path: root/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'db.py')
-rw-r--r--db.py38
1 files changed, 21 insertions, 17 deletions
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))