Only update category if hashtag was added

merge-requests/30/head
Bob Mottram 2022-04-24 18:19:41 +01:00
parent 3c17749dae
commit 726447e1cb
1 changed files with 14 additions and 8 deletions

View File

@ -249,11 +249,12 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str,
days_since_epoch = days_diff.days days_since_epoch = days_diff.days
tag_line = \ tag_line = \
str(days_since_epoch) + ' ' + nickname + ' ' + post_url + '\n' str(days_since_epoch) + ' ' + nickname + ' ' + post_url + '\n'
hashtags_ctr += 1 hashtag_added = False
if not os.path.isfile(tags_filename): if not os.path.isfile(tags_filename):
try: try:
with open(tags_filename, 'w+') as tags_file: with open(tags_filename, 'w+') as tags_file:
tags_file.write(tag_line) tags_file.write(tag_line)
hashtag_added = True
except OSError: except OSError:
print('EX: unable to write ' + tags_filename) print('EX: unable to write ' + tags_filename)
else: else:
@ -268,17 +269,22 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str,
try: try:
with open(tags_filename, 'w+') as tags_file: with open(tags_filename, 'w+') as tags_file:
tags_file.write(content) tags_file.write(content)
hashtag_added = True
except OSError as ex: except OSError as ex:
print('EX: Failed to write entry to tags file ' + print('EX: Failed to write entry to tags file ' +
tags_filename + ' ' + str(ex)) tags_filename + ' ' + str(ex))
# automatically assign a category to the tag if possible if hashtag_added:
category_filename = tags_dir + '/' + tag_name + '.category' hashtags_ctr += 1
if not os.path.isfile(category_filename):
category_str = \ # automatically assign a category to the tag if possible
guess_hashtag_category(tag_name, hashtag_categories) category_filename = tags_dir + '/' + tag_name + '.category'
if category_str: if not os.path.isfile(category_filename):
set_hashtag_category(base_dir, tag_name, category_str, False) category_str = \
guess_hashtag_category(tag_name, hashtag_categories)
if category_str:
set_hashtag_category(base_dir, tag_name,
category_str, False)
# if some hashtags were found then recalculate the swarm # if some hashtags were found then recalculate the swarm
# ready for later display # ready for later display