diff options
Diffstat (limited to 'parser.py')
| -rwxr-xr-x | parser.py | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -45,9 +45,9 @@ class MyRenderer(mistune.HTMLRenderer): ) def get_thought_from_id(db, id_): - title, datetime, markdown, redirect = db.get_thought(id_) + title, datetime, markdown, redirect, category_name = db.get_thought(id_) html, headers = parse_text(markdown) - return title, datetime, html, headers, redirect + return title, datetime, redirect, category_name, html, headers def parse_file(path): with open(path, "r") as f: @@ -114,6 +114,12 @@ def main(): type = str, required = True ) + s.add_argument( + "-c", "--category", + help = "Article category", + type = str, + required = True + ) for s in [export_parser, update_parser]: s.add_argument( @@ -142,8 +148,10 @@ def main(): with database.Database() as db: match verb: case "save": + if db.add_category(args["category"]): + print("Added category.") with open(args["markdown"], "r") as f: - db.add_thought(args["title"], f.read()) + db.add_thought(args["title"], f.read(), args["category"]) print("Added thought.") case "export": with open(args["out"], "w") as f: @@ -154,8 +162,8 @@ def main(): db.update_thought_markdown(args["id"], f.read()) print("Updated thought.") case "list": - for id_, title, datetime in db.get_all_thoughts(): - print(f"{id_}, {title}, {datetime}") + for id_, title, datetime, category in db.get_all_thoughts(): + print(f"{id_}, {title}, {datetime}, {category}") case _: print("Error! Unknown verb... Exiting...") exit() |
