From 62a0672667ce7a242048cdb433aa8f9ca65535a5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 2 Dec 2020 19:43:17 +0000 Subject: [PATCH] Show category swarm --- webapp_hashtagswarm.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/webapp_hashtagswarm.py b/webapp_hashtagswarm.py index e16a7d1aa..a6dd25703 100644 --- a/webapp_hashtagswarm.py +++ b/webapp_hashtagswarm.py @@ -9,6 +9,7 @@ __status__ = "Production" import os from datetime import datetime from utils import getHashtagCategories +from utils import getHashtagCategory def getHashtagCategoriesFeed(baseDir: str, @@ -112,6 +113,7 @@ def htmlHashTagSwarm(baseDir: str, actor: str, translate: {}) -> str: daysSinceEpochStr2 = str(daysSinceEpoch - 1) + ' ' recently = daysSinceEpoch - 1 tagSwarm = [] + categorySwarm = [] domainHistogram = {} # Load the blocked hashtags into memory. @@ -179,18 +181,36 @@ def htmlHashTagSwarm(baseDir: str, actor: str, translate: {}) -> str: else: domainHistogram[postDomain] = 1 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 if not tagSwarm: return '' tagSwarm.sort() + + # swarm of categories + categorySwarmStr = '' + if categorySwarm: + categorySwarm.sort() + for categoryStr in categorySwarm: + categorySwarmStr += \ + '' + categoryStr + '\n' + categorySwarmStr += '


\n' + + # swarm of tags tagSwarmStr = '' - ctr = 0 for tagName in tagSwarm: tagSwarmStr += \ '' + tagName + '\n' - ctr += 1 - tagSwarmHtml = tagSwarmStr.strip() + '\n' + + tagSwarmHtml = categorySwarmStr + tagSwarmStr.strip() + '\n' tagSwarmHtml += getHashtagDomainHistogram(domainHistogram, translate) return tagSwarmHtml