Less indentation

merge-requests/30/head
Bob Mottram 2023-09-02 12:47:24 +01:00
parent 62dcf97363
commit 9da08aeb6b
1 changed files with 26 additions and 24 deletions

View File

@ -60,36 +60,38 @@ def get_hashtag_categories(base_dir: str,
hashtag = catfile.split('.')[0] hashtag = catfile.split('.')[0]
if len(hashtag) > MAX_TAG_LENGTH: if len(hashtag) > MAX_TAG_LENGTH:
continue continue
category_str = None
with open(category_filename, 'r', encoding='utf-8') as fp_category: with open(category_filename, 'r', encoding='utf-8') as fp_category:
category_str = fp_category.read() category_str = fp_category.read()
if not category_str: if not category_str:
continue
if category:
# only return a dictionary for a specific category
if category_str != category:
continue continue
if category: if recent:
# only return a dictionary for a specific category tags_filename = base_dir + '/tags/' + hashtag + '.txt'
if category_str != category: if not os.path.isfile(tags_filename):
continue continue
mod_time_since_epoc = \
os.path.getmtime(tags_filename)
last_modified_date = \
datetime.datetime.fromtimestamp(mod_time_since_epoc)
file_days_since_epoch = \
(last_modified_date -
datetime.datetime(1970, 1, 1)).days
if file_days_since_epoch < recently:
continue
if recent: if not hashtag_categories.get(category_str):
tags_filename = base_dir + '/tags/' + hashtag + '.txt' hashtag_categories[category_str] = [hashtag]
if not os.path.isfile(tags_filename): else:
continue if hashtag not in hashtag_categories[category_str]:
mod_time_since_epoc = \ hashtag_categories[category_str].append(hashtag)
os.path.getmtime(tags_filename)
last_modified_date = \
datetime.datetime.fromtimestamp(mod_time_since_epoc)
file_days_since_epoch = \
(last_modified_date -
datetime.datetime(1970, 1, 1)).days
if file_days_since_epoch < recently:
continue
if not hashtag_categories.get(category_str):
hashtag_categories[category_str] = [hashtag]
else:
if hashtag not in hashtag_categories[category_str]:
hashtag_categories[category_str].append(hashtag)
break break
return hashtag_categories return hashtag_categories