Show category swarm

merge-requests/8/head
Bob Mottram 2020-12-02 19:43:17 +00:00
parent 1d63e5c94e
commit 62a0672667
1 changed files with 23 additions and 3 deletions

View File

@ -9,6 +9,7 @@ __status__ = "Production"
import os import os
from datetime import datetime from datetime import datetime
from utils import getHashtagCategories from utils import getHashtagCategories
from utils import getHashtagCategory
def getHashtagCategoriesFeed(baseDir: str, def getHashtagCategoriesFeed(baseDir: str,
@ -112,6 +113,7 @@ def htmlHashTagSwarm(baseDir: str, actor: str, translate: {}) -> str:
daysSinceEpochStr2 = str(daysSinceEpoch - 1) + ' ' daysSinceEpochStr2 = str(daysSinceEpoch - 1) + ' '
recently = daysSinceEpoch - 1 recently = daysSinceEpoch - 1
tagSwarm = [] tagSwarm = []
categorySwarm = []
domainHistogram = {} domainHistogram = {}
# Load the blocked hashtags into memory. # Load the blocked hashtags into memory.
@ -179,18 +181,36 @@ def htmlHashTagSwarm(baseDir: str, actor: str, translate: {}) -> str:
else: else:
domainHistogram[postDomain] = 1 domainHistogram[postDomain] = 1
tagSwarm.append(hashTagName) tagSwarm.append(hashTagName)
categoryFilename = \
tagsFilename.replace('.txt', '.category')
if os.path.isfile(categoryFilename):
categoryStr = \
getHashtagCategory(baseDir, hashTagName)
if categoryStr not in categorySwarm:
categorySwarm.append(categoryStr)
break break
if not tagSwarm: if not tagSwarm:
return '' return ''
tagSwarm.sort() tagSwarm.sort()
# swarm of categories
categorySwarmStr = ''
if categorySwarm:
categorySwarm.sort()
for categoryStr in categorySwarm:
categorySwarmStr += \
'<a href="' + actor + '/category/' + categoryStr + \
'" class="hashtagswarm">' + categoryStr + '</a>\n'
categorySwarmStr += '<br><br><br>\n'
# swarm of tags
tagSwarmStr = '' tagSwarmStr = ''
ctr = 0
for tagName in tagSwarm: for tagName in tagSwarm:
tagSwarmStr += \ tagSwarmStr += \
'<a href="' + actor + '/tags/' + tagName + \ '<a href="' + actor + '/tags/' + tagName + \
'" class="hashtagswarm">' + tagName + '</a>\n' '" class="hashtagswarm">' + tagName + '</a>\n'
ctr += 1
tagSwarmHtml = tagSwarmStr.strip() + '\n' tagSwarmHtml = categorySwarmStr + tagSwarmStr.strip() + '\n'
tagSwarmHtml += getHashtagDomainHistogram(domainHistogram, translate) tagSwarmHtml += getHashtagDomainHistogram(domainHistogram, translate)
return tagSwarmHtml return tagSwarmHtml