From 8ad13c94c793291ea7885f46f5c3020d3f2a5467 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 2 Dec 2020 13:38:07 +0000 Subject: [PATCH] Sort hashtag categories list --- utils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/utils.py b/utils.py index 8553a652..17255d2e 100644 --- a/utils.py +++ b/utils.py @@ -66,16 +66,24 @@ def getHashtagCategories(baseDir: str, category=None) -> None: def updateHashtagCategories(baseDir: str) -> None: """Regenerates the list of hashtag categories """ + categoryListFilename = baseDir + '/accounts/categoryList.txt' hashtagCategories = getHashtagCategories(baseDir) + if not hashtagCategories: + if os.path.isfile(categoryListFilename): + os.remove(categoryListFilename) + return + + categoryList = [] + for categoryStr, hashtagList in hashtagCategories.items(): + categoryList.append(categoryStr) + categoryList.sort() categoryListStr = '' - for categoryStr, hashtagList in hashtagCategories.items(): + for categoryStr in categoryList: categoryListStr += categoryStr + '\n' - if not hashtagCategories: - return # save a list of available categories for quick lookup - with open(baseDir + '/accounts/categoryList.txt', 'w+') as fp: + with open(categoryListFilename, 'w+') as fp: fp.write(categoryListStr)