Compare commits

...

3 Commits

Author SHA1 Message Date
dbd5c0f166 Merge branch 'master' into tagging 2022-07-08 12:04:00 -04:00
67c48f1255 Merge branch 'master' into tagging 2022-06-30 10:08:57 -04:00
c4db75dbad Properly close tag_file 2022-06-30 09:53:06 -04:00

View File

@ -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