Sort hashtag categories list

main
Bob Mottram 2020-12-02 13:38:07 +00:00
parent 61ee919a1f
commit 8ad13c94c7
1 changed files with 12 additions and 4 deletions

View File

@ -66,16 +66,24 @@ def getHashtagCategories(baseDir: str, category=None) -> None:
def updateHashtagCategories(baseDir: str) -> None: def updateHashtagCategories(baseDir: str) -> None:
"""Regenerates the list of hashtag categories """Regenerates the list of hashtag categories
""" """
categoryListFilename = baseDir + '/accounts/categoryList.txt'
hashtagCategories = getHashtagCategories(baseDir) 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 = '' categoryListStr = ''
for categoryStr, hashtagList in hashtagCategories.items(): for categoryStr in categoryList:
categoryListStr += categoryStr + '\n' categoryListStr += categoryStr + '\n'
if not hashtagCategories:
return
# save a list of available categories for quick lookup # 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) fp.write(categoryListStr)