Snake case

merge-requests/30/head
Bob Mottram 2021-12-27 17:16:57 +00:00
parent 2a57353f56
commit 9df47f2140
2 changed files with 25 additions and 25 deletions

View File

@ -447,22 +447,22 @@ def remove_html(content: str) -> str:
content = content.replace('<q>', '"').replace('</q>', '"') content = content.replace('<q>', '"').replace('</q>', '"')
content = content.replace('</p>', '\n\n').replace('<br>', '\n') content = content.replace('</p>', '\n\n').replace('<br>', '\n')
result = '' result = ''
for ch in content: for char in content:
if ch == '<': if char == '<':
removing = True removing = True
elif ch == '>': elif char == '>':
removing = False removing = False
elif not removing: elif not removing:
result += ch result += char
plain_text = result.replace(' ', ' ') plain_text = result.replace(' ', ' ')
# insert spaces after full stops # insert spaces after full stops
strLen = len(plain_text) str_len = len(plain_text)
result = '' result = ''
for i in range(strLen): for i in range(str_len):
result += plain_text[i] result += plain_text[i]
if plain_text[i] == '.' and i < strLen - 1: if plain_text[i] == '.' and i < str_len - 1:
if plain_text[i + 1] >= 'A' and plain_text[i + 1] <= 'Z': if plain_text[i + 1] >= 'A' and plain_text[i + 1] <= 'Z':
result += ' ' result += ' '
@ -485,7 +485,7 @@ def first_paragraph_from_string(content: str) -> str:
def is_system_account(nickname: str) -> bool: def is_system_account(nickname: str) -> bool:
"""Returns true if the given nickname is a system account """Returns true if the given nickname is a system account
""" """
if nickname == 'news' or nickname == 'inbox': if nickname in ('news', 'inbox'):
return True return True
return False return False
@ -518,10 +518,10 @@ def get_config_param(base_dir: str, variable_name: str):
""" """
_create_config(base_dir) _create_config(base_dir)
config_filename = base_dir + '/config.json' config_filename = base_dir + '/config.json'
configJson = load_json(config_filename) config_json = load_json(config_filename)
if configJson: if config_json:
if variable_name in configJson: if variable_name in config_json:
return configJson[variable_name] return config_json[variable_name]
return None return None
@ -536,8 +536,8 @@ def is_suspended(base_dir: str, nickname: str) -> bool:
suspended_filename = base_dir + '/accounts/suspended.txt' suspended_filename = base_dir + '/accounts/suspended.txt'
if os.path.isfile(suspended_filename): if os.path.isfile(suspended_filename):
with open(suspended_filename, 'r') as f: with open(suspended_filename, 'r') as susp_file:
lines = f.readlines() lines = susp_file.readlines()
for suspended in lines: for suspended in lines:
if suspended.strip('\n').strip('\r') == nickname: if suspended.strip('\n').strip('\r') == nickname:
return True return True
@ -554,8 +554,8 @@ def get_followers_list(base_dir: str,
if not os.path.isfile(filename): if not os.path.isfile(filename):
return [] return []
with open(filename, 'r') as f: with open(filename, 'r') as foll_file:
lines = f.readlines() lines = foll_file.readlines()
for i in range(len(lines)): for i in range(len(lines)):
lines[i] = lines[i].strip() lines[i] = lines[i].strip()
return lines return lines
@ -573,7 +573,7 @@ def get_followers_of_person(base_dir: str,
handle = nickname + '@' + domain handle = nickname + '@' + domain
if not os.path.isdir(base_dir + '/accounts/' + handle): if not os.path.isdir(base_dir + '/accounts/' + handle):
return followers return followers
for subdir, dirs, files in os.walk(base_dir + '/accounts'): for subdir, dirs, _ in os.walk(base_dir + '/accounts'):
for account in dirs: for account in dirs:
filename = os.path.join(subdir, account) + '/' + follow_file filename = os.path.join(subdir, account) + '/' + follow_file
if account == handle or \ if account == handle or \
@ -610,7 +610,7 @@ def remove_id_ending(id_str: str) -> str:
return id_str return id_str
def removeHashFromPostId(post_id: str) -> str: def remove_hash_from_post_id(post_id: str) -> str:
"""Removes any has from a post id """Removes any has from a post id
""" """
if '#' not in post_id: if '#' not in post_id:

View File

@ -23,7 +23,7 @@ from posts import postIsMuted
from posts import getPersonBox from posts import getPersonBox
from posts import downloadAnnounce from posts import downloadAnnounce
from posts import populateRepliesJson from posts import populateRepliesJson
from utils import removeHashFromPostId from utils import remove_hash_from_post_id
from utils import remove_html from utils import remove_html
from utils import get_actor_languages_list from utils import get_actor_languages_list
from utils import get_base_content_from_post from utils import get_base_content_from_post
@ -391,7 +391,7 @@ def _getReplyIconHtml(base_dir: str, nickname: str, domain: str,
return replyStr return replyStr
# reply is permitted - create reply icon # reply is permitted - create reply icon
replyToLink = removeHashFromPostId(post_json_object['object']['id']) replyToLink = remove_hash_from_post_id(post_json_object['object']['id'])
replyToLink = remove_id_ending(replyToLink) replyToLink = remove_id_ending(replyToLink)
# see Mike MacGirvin's replyTo suggestion # see Mike MacGirvin's replyTo suggestion
@ -573,7 +573,7 @@ def _getAnnounceIconHtml(isAnnounced: bool,
unannounceLinkStr = '?unannounce=' + \ unannounceLinkStr = '?unannounce=' + \
remove_id_ending(announceJsonObject['id']) remove_id_ending(announceJsonObject['id'])
announcePostId = removeHashFromPostId(post_json_object['object']['id']) announcePostId = remove_hash_from_post_id(post_json_object['object']['id'])
announcePostId = remove_id_ending(announcePostId) announcePostId = remove_id_ending(announcePostId)
announceLinkStr = '?' + \ announceLinkStr = '?' + \
announceLink + '=' + announcePostId + pageNumberParam announceLink + '=' + announcePostId + pageNumberParam
@ -642,7 +642,7 @@ def _getLikeIconHtml(nickname: str, domain_full: str,
likeStr += '<label class="likesCount">' likeStr += '<label class="likesCount">'
likeStr += likeCountStr.replace('(', '').replace(')', '').strip() likeStr += likeCountStr.replace('(', '').replace(')', '').strip()
likeStr += '</label>\n' likeStr += '</label>\n'
likePostId = removeHashFromPostId(post_json_object['id']) likePostId = remove_hash_from_post_id(post_json_object['id'])
likePostId = remove_id_ending(likePostId) likePostId = remove_id_ending(likePostId)
likeStr += \ likeStr += \
' <a class="imageAnchor" href="/users/' + nickname + '?' + \ ' <a class="imageAnchor" href="/users/' + nickname + '?' + \
@ -689,7 +689,7 @@ def _getBookmarkIconHtml(nickname: str, domain_full: str,
if translate.get(bookmarkTitle): if translate.get(bookmarkTitle):
bookmarkTitle = translate[bookmarkTitle] bookmarkTitle = translate[bookmarkTitle]
_logPostTiming(enableTimingLog, postStartTime, '12.6') _logPostTiming(enableTimingLog, postStartTime, '12.6')
bookmarkPostId = removeHashFromPostId(post_json_object['object']['id']) bookmarkPostId = remove_hash_from_post_id(post_json_object['object']['id'])
bookmarkPostId = remove_id_ending(bookmarkPostId) bookmarkPostId = remove_id_ending(bookmarkPostId)
bookmarkStr = \ bookmarkStr = \
' <a class="imageAnchor" href="/users/' + nickname + '?' + \ ' <a class="imageAnchor" href="/users/' + nickname + '?' + \
@ -727,7 +727,7 @@ def _getReactionIconHtml(nickname: str, domain_full: str,
if translate.get(reactionTitle): if translate.get(reactionTitle):
reactionTitle = translate[reactionTitle] reactionTitle = translate[reactionTitle]
_logPostTiming(enableTimingLog, postStartTime, '12.65') _logPostTiming(enableTimingLog, postStartTime, '12.65')
reactionPostId = removeHashFromPostId(post_json_object['object']['id']) reactionPostId = remove_hash_from_post_id(post_json_object['object']['id'])
reactionPostId = remove_id_ending(reactionPostId) reactionPostId = remove_id_ending(reactionPostId)
reactionStr = \ reactionStr = \
' <a class="imageAnchor" href="/users/' + nickname + \ ' <a class="imageAnchor" href="/users/' + nickname + \
@ -1372,7 +1372,7 @@ def individualPostAsHtml(signing_priv_key_pem: str,
avatarPosition = '' avatarPosition = ''
messageId = '' messageId = ''
if post_json_object.get('id'): if post_json_object.get('id'):
messageId = removeHashFromPostId(post_json_object['id']) messageId = remove_hash_from_post_id(post_json_object['id'])
messageId = remove_id_ending(messageId) messageId = remove_id_ending(messageId)
_logPostTiming(enableTimingLog, postStartTime, '2') _logPostTiming(enableTimingLog, postStartTime, '2')