Filter for recent hashtags on category screen

main
Bob Mottram 2020-12-05 16:06:36 +00:00
parent 09e980da24
commit d2f8d916f7
2 changed files with 20 additions and 2 deletions

View File

@ -38,11 +38,16 @@ def getHashtagCategory(baseDir: str, hashtag: str) -> str:
return ''
def getHashtagCategories(baseDir: str, category=None) -> None:
def getHashtagCategories(baseDir: str, recent=False, category=None) -> None:
"""Returns a dictionary containing hashtag categories
"""
hashtagCategories = {}
if recent:
currTime = datetime.datetime.utcnow()
daysSinceEpoch = (currTime - datetime.datetime(1970, 1, 1)).days
recently = daysSinceEpoch - 1
for subdir, dirs, files in os.walk(baseDir + '/tags'):
for f in files:
if not f.endswith('.category'):
@ -62,6 +67,19 @@ def getHashtagCategories(baseDir: str, category=None) -> None:
if categoryStr != category:
continue
if recent:
tagsFilename = baseDir + '/tags/' + hashtag + '.txt'
if os.path.isfile(tagsFilename):
modTimesinceEpoc = \
os.path.getmtime(tagsFilename)
lastModifiedDate = \
datetime.datetime.fromtimestamp(modTimesinceEpoc)
fileDaysSinceEpoch = \
(lastModifiedDate -
datetime.datetime(1970, 1, 1)).days
if fileDaysSinceEpoch < recently:
continue
if not hashtagCategories.get(categoryStr):
hashtagCategories[categoryStr] = [hashtag]
else:

View File

@ -279,7 +279,7 @@ def htmlSearchHashtagCategory(cssCache: {}, translate: {},
htmlStr += '<h1><a href="' + actor + '/search"><b>'
htmlStr += translate['Category'] + ': ' + categoryStr + '</b></a></h1>'
hashtagsDict = getHashtagCategories(baseDir, categoryStr)
hashtagsDict = getHashtagCategories(baseDir, True, categoryStr)
if hashtagsDict:
for categoryStr2, hashtagList in hashtagsDict.items():
hashtagList.sort()