mirror of https://gitlab.com/bashrc2/epicyon
Remove old hashtags when new ones are created
parent
85bb69ec66
commit
09d63088f0
2
inbox.py
2
inbox.py
|
@ -56,6 +56,7 @@ from posts import sendSignedJson
|
||||||
from posts import sendToFollowersThread
|
from posts import sendToFollowersThread
|
||||||
from webinterface import individualPostAsHtml
|
from webinterface import individualPostAsHtml
|
||||||
from webinterface import getIconsDir
|
from webinterface import getIconsDir
|
||||||
|
from webinterface import removeOldHashtags
|
||||||
from question import questionUpdateVotes
|
from question import questionUpdateVotes
|
||||||
from media import replaceYouTube
|
from media import replaceYouTube
|
||||||
from git import isGitPatch
|
from git import isGitPatch
|
||||||
|
@ -108,6 +109,7 @@ def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('WARN: Failed to write entry to tags file ' +
|
print('WARN: Failed to write entry to tags file ' +
|
||||||
tagsFilename + ' ' + str(e))
|
tagsFilename + ' ' + str(e))
|
||||||
|
removeOldHashtags(baseDir, 3)
|
||||||
|
|
||||||
|
|
||||||
def inboxStorePostToHtmlCache(recentPostsCache: {}, maxRecentPosts: int,
|
def inboxStorePostToHtmlCache(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
|
|
|
@ -5725,15 +5725,15 @@ def htmlCalendar(translate: {},
|
||||||
return calendarStr
|
return calendarStr
|
||||||
|
|
||||||
|
|
||||||
def htmlHashTagSwarm(baseDir: str, actor: str) -> str:
|
def removeOldHashtags(baseDir: str, maxMonths: int) -> str:
|
||||||
"""Returns a tag swarm of today's hashtags
|
"""Remove old hashtags
|
||||||
"""
|
"""
|
||||||
currTime = datetime.utcnow()
|
if maxMonths > 11:
|
||||||
daysSinceEpoch = (currTime - datetime(1970, 1, 1)).days
|
maxMonths = 11
|
||||||
maxDaysSinceEpoch = (currTime - datetime(1970, 3, 1)).days
|
maxDaysSinceEpoch = \
|
||||||
daysSinceEpochStr = str(daysSinceEpoch) + ' '
|
(datetime.utcnow() - datetime(1970, 1 + maxMonths, 1)).days
|
||||||
tagSwarm = []
|
|
||||||
removeHashtags = []
|
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)
|
||||||
|
@ -5743,10 +5743,35 @@ def htmlHashTagSwarm(baseDir: str, actor: str) -> str:
|
||||||
modTimesinceEpoc = os.path.getmtime(tagsFilename)
|
modTimesinceEpoc = os.path.getmtime(tagsFilename)
|
||||||
lastModifiedDate = datetime.fromtimestamp(modTimesinceEpoc)
|
lastModifiedDate = datetime.fromtimestamp(modTimesinceEpoc)
|
||||||
fileDaysSinceEpoch = (lastModifiedDate - datetime(1970, 1, 1)).days
|
fileDaysSinceEpoch = (lastModifiedDate - datetime(1970, 1, 1)).days
|
||||||
|
|
||||||
# check of the file is too old
|
# check of the file is too old
|
||||||
if fileDaysSinceEpoch < maxDaysSinceEpoch:
|
if fileDaysSinceEpoch < maxDaysSinceEpoch:
|
||||||
removeHashtags.append(tagsFilename)
|
removeHashtags.append(tagsFilename)
|
||||||
|
|
||||||
|
for removeFilename in removeHashtags:
|
||||||
|
try:
|
||||||
|
os.remove(removeFilename)
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def htmlHashTagSwarm(baseDir: str, actor: str) -> str:
|
||||||
|
"""Returns a tag swarm of today's hashtags
|
||||||
|
"""
|
||||||
|
currTime = datetime.utcnow()
|
||||||
|
daysSinceEpoch = (currTime - datetime(1970, 1, 1)).days
|
||||||
|
daysSinceEpochStr = str(daysSinceEpoch) + ' '
|
||||||
|
tagSwarm = []
|
||||||
|
|
||||||
|
for subdir, dirs, files in os.walk(baseDir + '/tags'):
|
||||||
|
for f in files:
|
||||||
|
tagsFilename = os.path.join(baseDir + '/tags', f)
|
||||||
|
if not os.path.isfile(tagsFilename):
|
||||||
continue
|
continue
|
||||||
|
# get last modified datetime
|
||||||
|
modTimesinceEpoc = os.path.getmtime(tagsFilename)
|
||||||
|
lastModifiedDate = datetime.fromtimestamp(modTimesinceEpoc)
|
||||||
|
fileDaysSinceEpoch = (lastModifiedDate - datetime(1970, 1, 1)).days
|
||||||
# check if the file was last modified today
|
# check if the file was last modified today
|
||||||
if fileDaysSinceEpoch != daysSinceEpoch:
|
if fileDaysSinceEpoch != daysSinceEpoch:
|
||||||
continue
|
continue
|
||||||
|
@ -5791,13 +5816,6 @@ def htmlHashTagSwarm(baseDir: str, actor: str) -> str:
|
||||||
if lineCtr >= maxLineCtr:
|
if lineCtr >= maxLineCtr:
|
||||||
break
|
break
|
||||||
|
|
||||||
# remove old hashtags
|
|
||||||
for removeFilename in removeHashtags:
|
|
||||||
try:
|
|
||||||
os.remove(removeFilename)
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if not tagSwarm:
|
if not tagSwarm:
|
||||||
return ''
|
return ''
|
||||||
tagSwarm.sort()
|
tagSwarm.sort()
|
||||||
|
|
Loading…
Reference in New Issue