From cf96d38b9db01a0098c0f8418826230832f2ba86 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 19 Aug 2019 13:13:18 +0100 Subject: [PATCH] Add mention tags --- content.py | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/content.py b/content.py index 2a898efd..8f8abbf6 100644 --- a/content.py +++ b/content.py @@ -97,7 +97,7 @@ def addEmoji(baseDir: str,wordStr: str,httpPrefix: str,domain: str,replaceEmoji: "\""+emoji+"\"" return True -def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},recipients: [],tagsList: []) -> bool: +def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},recipients: [],tags: {}) -> bool: """Detects mentions and adds them to the replacements dict and recipients list """ if not wordStr.startswith('@'): @@ -117,11 +117,11 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r recipientActor=httpPrefix+"://"+replaceDomain+"/users/"+possibleNickname if recipientActor not in recipients: recipients.append(recipientActor) - tagsList.append({ - 'href': recipientActor, - 'name': wordStr, - 'type': 'Mention' - }) + tags[wordStr]={ + 'href': recipientActor, + 'name': wordStr, + 'type': 'Mention' + } replaceMentions[wordStr]="@"+possibleNickname+"" return True return False @@ -134,11 +134,11 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r recipientActor=httpPrefix+"://"+possibleDomain+"/users/"+possibleNickname if recipientActor not in recipients: recipients.append(recipientActor) - tagsList.append({ - 'href': recipientActor, - 'name': wordStr, - 'type': 'Mention' - }) + tags[wordStr]={ + 'href': recipientActor, + 'name': wordStr, + 'type': 'Mention' + } replaceMentions[wordStr]="@"+possibleNickname+"" return True # @nick@domain @@ -148,11 +148,11 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r recipientActor=httpPrefix+"://"+possibleDomain+"/users/"+possibleNickname if recipientActor not in recipients: recipients.append(recipientActor) - tagsList.append({ - 'href': recipientActor, - 'name': wordStr, - 'type': 'Mention' - }) + tags[wordStr]={ + 'href': recipientActor, + 'name': wordStr, + 'type': 'Mention' + } replaceMentions[wordStr]="@"+possibleNickname+"" return True return False @@ -199,12 +199,8 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \ # extract mentions and tags from words for wordStr in words: - tagsList=[] - if addMention(wordStr,httpPrefix,following,replaceMentions,recipients,tagsList): - for tag in tagsList: - hashtags[tag['name']]=tag + if addMention(wordStr,httpPrefix,following,replaceMentions,recipients,hashtags): continue - tagsList=[] if addHashTags(wordStr,httpPrefix,originalDomain,replaceHashTags,hashtags): continue if len(wordStr)>2 and wordStr.startswith(':') and wordStr.endswith(':') and not emojiDict: