Remove old hashtag indexes

main
Bob Mottram 2020-05-31 12:48:41 +01:00
parent 9bbfd3d4cf
commit 9dd77fa4e1
1 changed files with 24 additions and 17 deletions

View File

@ -5728,15 +5728,23 @@ def htmlCalendar(translate: {},
def htmlHashTagSwarm(baseDir: str, actor: str) -> str: def htmlHashTagSwarm(baseDir: str, actor: str) -> str:
"""Returns a tag swarm of today's hashtags """Returns a tag swarm of today's hashtags
""" """
daysSinceEpoch = (datetime.utcnow() - datetime(1970, 1, 1)).days currTime = datetime.utcnow()
daysSinceEpoch = (currTime - datetime(1970, 1, 1)).days
maxDaysSinceEpoch = (currTime - datetime(1970, 3, 1)).days
daysSinceEpochStr = str(daysSinceEpoch) + ' ' daysSinceEpochStr = str(daysSinceEpoch) + ' '
tagSwarm = [] tagSwarm = []
tagSwarmCtr = [] removeHashtags = []
for subdir, dirs, files in os.walk(baseDir + '/tags'): for subdir, dirs, files in os.walk(baseDir + '/tags'):
for f in files: for f in files:
tagsFilename = os.path.join(baseDir + '/tags', f) tagsFilename = os.path.join(baseDir + '/tags', f)
if not os.path.isfile(tagsFilename): if not os.path.isfile(tagsFilename):
continue continue
lastModifiedDate = os.stat(tagsFilename)
fileDaysSinceEpoch = (lastModifiedDate - datetime(1970, 1, 1)).days
if fileDaysSinceEpoch < maxDaysSinceEpoch:
removeHashtags.append(tagsFilename)
continue
hashTagName = f.split('.')[0] hashTagName = f.split('.')[0]
if isBlockedHashtag(baseDir, hashTagName): if isBlockedHashtag(baseDir, hashTagName):
continue continue
@ -5746,12 +5754,13 @@ def htmlHashTagSwarm(baseDir: str, actor: str) -> str:
line = tagsFile.readline() line = tagsFile.readline()
lineCtr = 1 lineCtr = 1
tagCtr = 0 tagCtr = 0
maxLineCtr = 4
while line: while line:
if ' ' not in line: if ' ' not in line:
line = tagsFile.readline() line = tagsFile.readline()
lineCtr += 1 lineCtr += 1
# don't read too many lines # don't read too many lines
if lineCtr > 4: if lineCtr > maxLineCtr:
break break
continue continue
postDaysSinceEpochStr = line.split(' ')[0] postDaysSinceEpochStr = line.split(' ')[0]
@ -5759,7 +5768,7 @@ def htmlHashTagSwarm(baseDir: str, actor: str) -> str:
line = tagsFile.readline() line = tagsFile.readline()
lineCtr += 1 lineCtr += 1
# don't read too many lines # don't read too many lines
if lineCtr > 4: if lineCtr > maxLineCtr:
break break
continue continue
postDaysSinceEpoch = int(postDaysSinceEpochStr) postDaysSinceEpoch = int(postDaysSinceEpochStr)
@ -5769,31 +5778,29 @@ def htmlHashTagSwarm(baseDir: str, actor: str) -> str:
if tagCtr == 0: if tagCtr == 0:
tagSwarm.append(hashTagName) tagSwarm.append(hashTagName)
tagCtr += 1 tagCtr += 1
if tagCtr > 3:
break
line = tagsFile.readline() line = tagsFile.readline()
lineCtr += 1 lineCtr += 1
# don't read too many lines # don't read too many lines
if lineCtr > 4: if lineCtr > maxLineCtr:
break break
if tagCtr > 0: # remove old hashtags
tagSwarmCtr.append(tagCtr) for removeFilename in removeHashtags:
try:
os.remove(removeFilename)
except BaseException:
pass
if not tagSwarm: if not tagSwarm:
return '' return ''
tagSwarm.sort() tagSwarm.sort()
tagSwarmStr = '' tagSwarmStr = ''
ctr = 0 ctr = 0
for tagName in tagSwarm: for tagName in tagSwarm:
if tagSwarmCtr[ctr] < 4: tagSwarmStr += \
tagSwarmStr += \ '<a href="' + actor + '/tags/' + tagName + \
'<a href="' + actor + '/tags/' + tagName + \ '" class="hashtagswarm">' + tagName + '</a> '
'" class="hashtagswarm">' + tagName + '</a> '
else:
tagSwarmStr += \
'<a href="' + actor + '/tags/' + tagName + \
'" class="hashtagswarm2">' + tagName + '</a> '
ctr += 1 ctr += 1
tagSwarmHtml = tagSwarmStr.strip() + '\n' tagSwarmHtml = tagSwarmStr.strip() + '\n'
return tagSwarmHtml return tagSwarmHtml