From c4db75dbad9fb60993a920b9ca302ff0c47464c6 Mon Sep 17 00:00:00 2001 From: 20xd6 <20xd6@airmail.cc> Date: Thu, 30 Jun 2022 09:53:06 -0400 Subject: [PATCH] Properly close tag_file --- tagging.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/tagging.py b/tagging.py index 6505d0e..7102db7 100644 --- a/tagging.py +++ b/tagging.py @@ -1,7 +1,49 @@ import csv +import os + +from bs4 import BeautifulSoup + +import find_ini + +blog_config = find_ini.return_options() +web_root = blog_config['general']['web_root'] +sub_folder = blog_config['general']['sub_folder'] def get_tags(): user_tags = input("Please enter tags for the article separated by commas: ") - csv_reader = csv.reader(user_tags) - article_tags = [tuple(row) for row in csv_reader] + # csv_reader = csv.reader(user_tags) + # article_tags = [tuple(row) for row in csv_reader] + return user_tags + + +def tag_article(path_to_publish): + article_tags = get_tags() + tag_file = open(path_to_publish + "/tags", "w") + tag_file.write(article_tags) + tag_file.close() + existing_tags = get_existing_tags() + print("Existing Tags: ", existing_tags) + + +def get_existing_tags(): + tags_path = os.path.join(web_root, sub_folder, "by_tag", "tags.csv") + with open(tags_path, "r", newline='') as tags_source: + tags_text = tags_source.read() + print(tags_text) + csv_reader = csv.DictReader(tags_text, delimiter=',') + dict_from_csv = csv_reader + print(list(dict_from_csv)) + print(csv_reader.dialect) + line_count = 0 + for row in csv_reader: + print(row) + if line_count == 0: + print(f'Column names are {", ".join(row)}') + line_count += 1 + else: + print(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.') + line_count += 1 + print(f'Processed {line_count} lines.') + existing_tags = [x[0] for x in csv_reader] + return existing_tags