Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
dbd5c0f166 | |||
67c48f1255 | |||
c4db75dbad |
46
tagging.py
46
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user