forked from indymedia/epicyon
Tidying
parent
34140b6ee9
commit
5a002e7d5e
67
content.py
67
content.py
|
@ -100,10 +100,6 @@ def addHashTags(wordStr: str,httpPrefix: str,domain: str,replaceHashTags: {},pos
|
||||||
"""Detects hashtags and adds them to the replacements dict
|
"""Detects hashtags and adds them to the replacements dict
|
||||||
Also updates the hashtags list to be added to the post
|
Also updates the hashtags list to be added to the post
|
||||||
"""
|
"""
|
||||||
if not wordStr.startswith('#'):
|
|
||||||
return False
|
|
||||||
if len(wordStr)<2:
|
|
||||||
return False
|
|
||||||
if replaceHashTags.get(wordStr):
|
if replaceHashTags.get(wordStr):
|
||||||
return True
|
return True
|
||||||
hashtag=wordStr[1:]
|
hashtag=wordStr[1:]
|
||||||
|
@ -182,10 +178,6 @@ def addEmoji(baseDir: str,wordStr: str,httpPrefix: str,domain: str,replaceEmoji:
|
||||||
def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},recipients: [],tags: {}) -> 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
|
"""Detects mentions and adds them to the replacements dict and recipients list
|
||||||
"""
|
"""
|
||||||
if not wordStr.startswith('@'):
|
|
||||||
return False
|
|
||||||
if len(wordStr)<2:
|
|
||||||
return False
|
|
||||||
possibleHandle=wordStr[1:]
|
possibleHandle=wordStr[1:]
|
||||||
# @nick
|
# @nick
|
||||||
if following and '@' not in possibleHandle:
|
if following and '@' not in possibleHandle:
|
||||||
|
@ -238,22 +230,22 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def removeLongWords(content: str,maxWordLength: int) -> str:
|
def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
|
||||||
"""Breaks up long words so that on mobile screens this doesn't disrupt the layout
|
"""Breaks up long words so that on mobile screens this doesn't disrupt the layout
|
||||||
"""
|
"""
|
||||||
words=content.split(' ')
|
words=content.split(' ')
|
||||||
for wordStr in words:
|
for wordStr in longWordsList:
|
||||||
if not wordStr.startswith('<'):
|
if wordStr.startswith('<'):
|
||||||
if len(wordStr)>maxWordLength:
|
continue
|
||||||
if len(wordStr[maxWordLength:])<maxWordLength:
|
if len(wordStr[maxWordLength:])<maxWordLength:
|
||||||
content= \
|
content= \
|
||||||
content.replace(wordStr, \
|
content.replace(wordStr, \
|
||||||
wordStr[:maxWordLength]+'\n'+ \
|
wordStr[:maxWordLength]+'\n'+ \
|
||||||
wordStr[maxWordLength:])
|
wordStr[maxWordLength:])
|
||||||
else:
|
else:
|
||||||
content= \
|
content= \
|
||||||
content.replace(wordStr, \
|
content.replace(wordStr, \
|
||||||
wordStr[:maxWordLength])
|
wordStr[:maxWordLength])
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def addHtmlTags(baseDir: str,httpPrefix: str, \
|
def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||||
|
@ -294,21 +286,26 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||||
# read the following list so that we can detect just @nick
|
# read the following list so that we can detect just @nick
|
||||||
# in addition to @nick@domain
|
# in addition to @nick@domain
|
||||||
following=None
|
following=None
|
||||||
if os.path.isfile(followingFilename):
|
if '@' in words:
|
||||||
with open(followingFilename, "r") as f:
|
if os.path.isfile(followingFilename):
|
||||||
following = f.readlines()
|
with open(followingFilename, "r") as f:
|
||||||
|
following = f.readlines()
|
||||||
|
|
||||||
# extract mentions and tags from words
|
# extract mentions and tags from words
|
||||||
longWordsExist=False
|
longWordsList=[]
|
||||||
for wordStr in words:
|
for wordStr in words:
|
||||||
if len(wordStr)>maxWordLength:
|
wordLen=len(wordStr)
|
||||||
longWordsExist=True
|
if wordLen>2:
|
||||||
if addMention(wordStr,httpPrefix,following,replaceMentions,recipients,hashtags):
|
if wordLen>maxWordLength:
|
||||||
continue
|
longWordsList.append(wordStr)
|
||||||
if addHashTags(wordStr,httpPrefix,originalDomain,replaceHashTags,hashtags):
|
firstChar=wordStr[0]
|
||||||
continue
|
if firstChar=='@':
|
||||||
if len(wordStr)>2:
|
if addMention(wordStr,httpPrefix,following,replaceMentions,recipients,hashtags):
|
||||||
if ':' in wordStr:
|
continue
|
||||||
|
elif firstChar=='#':
|
||||||
|
if addHashTags(wordStr,httpPrefix,originalDomain,replaceHashTags,hashtags):
|
||||||
|
continue
|
||||||
|
elif ':' in wordStr:
|
||||||
#print('TAG: emoji located - '+wordStr)
|
#print('TAG: emoji located - '+wordStr)
|
||||||
wordStr2=wordStr.split(':')[1]
|
wordStr2=wordStr.split(':')[1]
|
||||||
if not emojiDict:
|
if not emojiDict:
|
||||||
|
@ -343,8 +340,8 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||||
content=content.replace(wordStr,replaceStr)
|
content=content.replace(wordStr,replaceStr)
|
||||||
|
|
||||||
content=addWebLinks(content)
|
content=addWebLinks(content)
|
||||||
if longWordsExist:
|
if longWordsList:
|
||||||
content=removeLongWords(content,maxWordLength)
|
content=removeLongWords(content,maxWordLength,longWordsList)
|
||||||
content=content.replace(' --linebreak-- ','</p><p>')
|
content=content.replace(' --linebreak-- ','</p><p>')
|
||||||
return '<p>'+content+'</p>'
|
return '<p>'+content+'</p>'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue