Snake case

main
Bob Mottram 2022-01-04 10:13:28 +00:00
parent 74e953ce3b
commit 347691bddc
1 changed files with 213 additions and 208 deletions

View File

@ -32,9 +32,9 @@ from session import create_session
def html_moderation(css_cache: {}, default_timeline: str,
recent_posts_cache: {}, max_recent_posts: int,
translate: {}, pageNumber: int, itemsPerPage: int,
translate: {}, page_number: int, items_per_page: int,
session, base_dir: str, wf_request: {}, person_cache: {},
nickname: str, domain: str, port: int, inboxJson: {},
nickname: str, domain: str, port: int, inbox_json: {},
allow_deletion: bool,
http_prefix: str, project_version: str,
yt_replace_domain: str,
@ -46,7 +46,7 @@ def html_moderation(css_cache: {}, default_timeline: str,
icons_as_buttons: bool,
rss_icon_at_top: bool,
publish_button_at_top: bool,
authorized: bool, moderationActionStr: str,
authorized: bool, moderation_action_str: str,
theme: str, peertube_instances: [],
allow_local_network_access: bool,
text_mode_banner: str,
@ -61,10 +61,10 @@ def html_moderation(css_cache: {}, default_timeline: str,
artist = is_artist(base_dir, nickname)
return html_timeline(css_cache, default_timeline,
recent_posts_cache, max_recent_posts,
translate, pageNumber,
itemsPerPage, session, base_dir,
translate, page_number,
items_per_page, session, base_dir,
wf_request, person_cache,
nickname, domain, port, inboxJson, 'moderation',
nickname, domain, port, inbox_json, 'moderation',
allow_deletion, http_prefix,
project_version, True, False,
yt_replace_domain,
@ -75,7 +75,7 @@ def html_moderation(css_cache: {}, default_timeline: str,
full_width_tl_button_header,
icons_as_buttons, rss_icon_at_top,
publish_button_at_top,
authorized, moderationActionStr, theme,
authorized, moderation_action_str, theme,
peertube_instances, allow_local_network_access,
text_mode_banner, access_keys, system_language,
max_like_count, shared_items_federated_domains,
@ -85,37 +85,37 @@ def html_moderation(css_cache: {}, default_timeline: str,
def html_account_info(css_cache: {}, translate: {},
base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int,
searchHandle: str, debug: bool,
search_handle: str, debug: bool,
system_language: str, signing_priv_key_pem: str) -> str:
"""Shows which domains a search handle interacts with.
This screen is shown if a moderator enters a handle and selects info
on the moderation screen
"""
signing_priv_key_pem = None
msgStr1 = 'This account interacts with the following instances'
msg_str1 = 'This account interacts with the following instances'
infoForm = ''
info_form = ''
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instanceTitle = \
instance_title = \
get_config_param(base_dir, 'instanceTitle')
infoForm = \
html_header_with_external_style(css_filename, instanceTitle, None)
info_form = \
html_header_with_external_style(css_filename, instance_title, None)
searchNickname = get_nickname_from_actor(searchHandle)
searchDomain, searchPort = get_domain_from_actor(searchHandle)
search_nickname = get_nickname_from_actor(search_handle)
search_domain, search_port = get_domain_from_actor(search_handle)
searchHandle = searchNickname + '@' + searchDomain
searchActor = \
local_actor_url(http_prefix, searchNickname, searchDomain)
infoForm += \
search_handle = search_nickname + '@' + search_domain
search_actor = \
local_actor_url(http_prefix, search_nickname, search_domain)
info_form += \
'<center><h1><a href="/users/' + nickname + '/moderation">' + \
translate['Account Information'] + ':</a> <a href="' + searchActor + \
'">' + searchHandle + '</a></h1><br>\n'
translate['Account Information'] + ':</a> <a href="' + search_actor + \
'">' + search_handle + '</a></h1><br>\n'
infoForm += translate[msgStr1] + '</center><br><br>\n'
info_form += translate[msg_str1] + '</center><br><br>\n'
proxy_type = 'tor'
if not os.path.isfile('/usr/bin/tor'):
@ -125,183 +125,188 @@ def html_account_info(css_cache: {}, translate: {},
session = create_session(proxy_type)
wordFrequency = {}
originDomain = None
domainDict = get_public_post_info(session,
base_dir, searchNickname, searchDomain,
originDomain,
proxy_type, searchPort,
http_prefix, debug,
__version__, wordFrequency,
system_language,
signing_priv_key_pem)
word_frequency = {}
origin_domain = None
domain_dict = get_public_post_info(session, base_dir,
search_nickname, search_domain,
origin_domain,
proxy_type, search_port,
http_prefix, debug,
__version__, word_frequency,
system_language,
signing_priv_key_pem)
# get a list of any blocked followers
followersList = \
followers_list = \
download_follow_collection(signing_priv_key_pem,
'followers', session,
http_prefix, searchActor, 1, 5, debug)
blockedFollowers = []
for followerActor in followersList:
followerNickname = get_nickname_from_actor(followerActor)
followerDomain, followerPort = get_domain_from_actor(followerActor)
followerDomainFull = get_full_domain(followerDomain, followerPort)
http_prefix, search_actor, 1, 5, debug)
blocked_followers = []
for follower_actor in followers_list:
follower_nickname = get_nickname_from_actor(follower_actor)
follower_domain, follower_port = get_domain_from_actor(follower_actor)
follower_domain_full = get_full_domain(follower_domain, follower_port)
if is_blocked(base_dir, nickname, domain,
followerNickname, followerDomainFull):
blockedFollowers.append(followerActor)
follower_nickname, follower_domain_full):
blocked_followers.append(follower_actor)
# get a list of any blocked following
followingList = \
following_list = \
download_follow_collection(signing_priv_key_pem,
'following', session,
http_prefix, searchActor, 1, 5, debug)
blockedFollowing = []
for followingActor in followingList:
followingNickname = get_nickname_from_actor(followingActor)
followingDomain, followingPort = get_domain_from_actor(followingActor)
followingDomainFull = get_full_domain(followingDomain, followingPort)
http_prefix, search_actor, 1, 5, debug)
blocked_following = []
for following_actor in following_list:
following_nickname = get_nickname_from_actor(following_actor)
following_domain, following_port = \
get_domain_from_actor(following_actor)
following_domain_full = \
get_full_domain(following_domain, following_port)
if is_blocked(base_dir, nickname, domain,
followingNickname, followingDomainFull):
blockedFollowing.append(followingActor)
following_nickname, following_domain_full):
blocked_following.append(following_actor)
infoForm += '<div class="accountInfoDomains">\n'
usersPath = '/users/' + nickname + '/accountinfo'
info_form += '<div class="accountInfoDomains">\n'
users_path = '/users/' + nickname + '/accountinfo'
ctr = 1
for postDomain, blockedPostUrls in domainDict.items():
infoForm += '<a href="' + \
http_prefix + '://' + postDomain + '" ' + \
for post_domain, blocked_post_urls in domain_dict.items():
info_form += '<a href="' + \
http_prefix + '://' + post_domain + '" ' + \
'target="_blank" rel="nofollow noopener noreferrer">' + \
postDomain + '</a> '
if is_blocked_domain(base_dir, postDomain):
blockedPostsLinks = ''
urlCtr = 0
for url in blockedPostUrls:
if urlCtr > 0:
blockedPostsLinks += '<br>'
blockedPostsLinks += \
post_domain + '</a> '
if is_blocked_domain(base_dir, post_domain):
blocked_posts_links = ''
url_ctr = 0
for url in blocked_post_urls:
if url_ctr > 0:
blocked_posts_links += '<br>'
blocked_posts_links += \
'<a href="' + url + '" ' + \
'target="_blank" rel="nofollow noopener noreferrer">' + \
url + '</a>'
urlCtr += 1
blockedPostsHtml = ''
if blockedPostsLinks:
blockNoStr = 'blockNumber' + str(ctr)
blockedPostsHtml = \
get_content_warning_button(blockNoStr,
translate, blockedPostsLinks)
url_ctr += 1
blocked_posts_html = ''
if blocked_posts_links:
block_no_str = 'blockNumber' + str(ctr)
blocked_posts_html = \
get_content_warning_button(block_no_str,
translate,
blocked_posts_links)
ctr += 1
infoForm += \
'<a href="' + usersPath + '?unblockdomain=' + postDomain + \
'?handle=' + searchHandle + '">'
infoForm += '<button class="buttonhighlighted"><span>' + \
info_form += \
'<a href="' + users_path + '?unblockdomain=' + post_domain + \
'?handle=' + search_handle + '">'
info_form += '<button class="buttonhighlighted"><span>' + \
translate['Unblock'] + '</span></button></a> ' + \
blockedPostsHtml + '\n'
blocked_posts_html + '\n'
else:
infoForm += \
'<a href="' + usersPath + '?blockdomain=' + postDomain + \
'?handle=' + searchHandle + '">'
if postDomain != domain:
infoForm += '<button class="button"><span>' + \
info_form += \
'<a href="' + users_path + '?blockdomain=' + post_domain + \
'?handle=' + search_handle + '">'
if post_domain != domain:
info_form += '<button class="button"><span>' + \
translate['Block'] + '</span></button>'
infoForm += '</a>\n'
infoForm += '<br>\n'
info_form += '</a>\n'
info_form += '<br>\n'
infoForm += '</div>\n'
info_form += '</div>\n'
if blockedFollowing:
blockedFollowing.sort()
infoForm += '<div class="accountInfoDomains">\n'
infoForm += '<h1>' + translate['Blocked following'] + '</h1>\n'
infoForm += \
if blocked_following:
blocked_following.sort()
info_form += '<div class="accountInfoDomains">\n'
info_form += '<h1>' + translate['Blocked following'] + '</h1>\n'
info_form += \
'<p>' + \
translate['Receives posts from the following accounts'] + \
':</p>\n'
for actor in blockedFollowing:
followingNickname = get_nickname_from_actor(actor)
followingDomain, followingPort = get_domain_from_actor(actor)
followingDomainFull = \
get_full_domain(followingDomain, followingPort)
infoForm += '<a href="' + actor + '" ' + \
for actor in blocked_following:
following_nickname = get_nickname_from_actor(actor)
following_domain, following_port = get_domain_from_actor(actor)
following_domain_full = \
get_full_domain(following_domain, following_port)
info_form += '<a href="' + actor + '" ' + \
'target="_blank" rel="nofollow noopener noreferrer">' + \
followingNickname + '@' + followingDomainFull + \
following_nickname + '@' + following_domain_full + \
'</a><br><br>\n'
infoForm += '</div>\n'
info_form += '</div>\n'
if blockedFollowers:
blockedFollowers.sort()
infoForm += '<div class="accountInfoDomains">\n'
infoForm += '<h1>' + translate['Blocked followers'] + '</h1>\n'
infoForm += \
if blocked_followers:
blocked_followers.sort()
info_form += '<div class="accountInfoDomains">\n'
info_form += '<h1>' + translate['Blocked followers'] + '</h1>\n'
info_form += \
'<p>' + \
translate['Sends out posts to the following accounts'] + \
':</p>\n'
for actor in blockedFollowers:
followerNickname = get_nickname_from_actor(actor)
followerDomain, followerPort = get_domain_from_actor(actor)
followerDomainFull = get_full_domain(followerDomain, followerPort)
infoForm += '<a href="' + actor + '" ' + \
for actor in blocked_followers:
follower_nickname = get_nickname_from_actor(actor)
follower_domain, follower_port = get_domain_from_actor(actor)
follower_domain_full = \
get_full_domain(follower_domain, follower_port)
info_form += '<a href="' + actor + '" ' + \
'target="_blank" rel="nofollow noopener noreferrer">' + \
followerNickname + '@' + followerDomainFull + '</a><br><br>\n'
infoForm += '</div>\n'
follower_nickname + '@' + \
follower_domain_full + '</a><br><br>\n'
info_form += '</div>\n'
if wordFrequency:
maxCount = 1
for word, count in wordFrequency.items():
if count > maxCount:
maxCount = count
minimumWordCount = int(maxCount / 2)
if minimumWordCount >= 3:
infoForm += '<div class="accountInfoDomains">\n'
infoForm += '<h1>' + translate['Word frequencies'] + '</h1>\n'
wordSwarm = ''
if word_frequency:
max_count = 1
for word, count in word_frequency.items():
if count > max_count:
max_count = count
minimum_word_count = int(max_count / 2)
if minimum_word_count >= 3:
info_form += '<div class="accountInfoDomains">\n'
info_form += '<h1>' + translate['Word frequencies'] + '</h1>\n'
word_swarm = ''
ctr = 0
for word, count in wordFrequency.items():
if count >= minimumWordCount:
for word, count in word_frequency.items():
if count >= minimum_word_count:
if ctr > 0:
wordSwarm += ' '
if count < maxCount - int(maxCount / 4):
wordSwarm += word
word_swarm += ' '
if count < max_count - int(max_count / 4):
word_swarm += word
else:
if count != maxCount:
wordSwarm += '<b>' + word + '</b>'
if count != max_count:
word_swarm += '<b>' + word + '</b>'
else:
wordSwarm += '<b><i>' + word + '</i></b>'
word_swarm += '<b><i>' + word + '</i></b>'
ctr += 1
infoForm += wordSwarm
infoForm += '</div>\n'
info_form += word_swarm
info_form += '</div>\n'
infoForm += html_footer()
return infoForm
info_form += html_footer()
return info_form
def html_moderation_info(css_cache: {}, translate: {},
base_dir: str, http_prefix: str,
nickname: str) -> str:
msgStr1 = \
msg_str1 = \
'These are globally blocked for all accounts on this instance'
msgStr2 = \
msg_str2 = \
'Any blocks or suspensions made by moderators will be shown here.'
infoForm = ''
info_form = ''
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instanceTitle = \
instance_title = \
get_config_param(base_dir, 'instanceTitle')
infoForm = html_header_with_external_style(css_filename,
instanceTitle, None)
info_form = html_header_with_external_style(css_filename,
instance_title, None)
infoForm += \
info_form += \
'<center><h1><a href="/users/' + nickname + '/moderation">' + \
translate['Moderation Information'] + \
'</a></h1></center><br>'
infoShown = False
info_shown = False
accounts = []
for subdir, dirs, files in os.walk(base_dir + '/accounts'):
for _, dirs, _ in os.walk(base_dir + '/accounts'):
for acct in dirs:
if not is_account_dir(acct):
continue
@ -311,107 +316,107 @@ def html_moderation_info(css_cache: {}, translate: {},
cols = 5
if len(accounts) > 10:
infoForm += '<details><summary><b>' + translate['Show Accounts']
infoForm += '</b></summary>\n'
infoForm += '<div class="container">\n'
infoForm += '<table class="accountsTable">\n'
infoForm += ' <colgroup>\n'
info_form += '<details><summary><b>' + translate['Show Accounts']
info_form += '</b></summary>\n'
info_form += '<div class="container">\n'
info_form += '<table class="accountsTable">\n'
info_form += ' <colgroup>\n'
for col in range(cols):
infoForm += ' <col span="1" class="accountsTableCol">\n'
infoForm += ' </colgroup>\n'
infoForm += '<tr>\n'
info_form += ' <col span="1" class="accountsTableCol">\n'
info_form += ' </colgroup>\n'
info_form += '<tr>\n'
col = 0
for acct in accounts:
acctNickname = acct.split('@')[0]
accountDir = os.path.join(base_dir + '/accounts', acct)
actor_json = load_json(accountDir + '.json')
acct_nickname = acct.split('@')[0]
account_dir = os.path.join(base_dir + '/accounts', acct)
actor_json = load_json(account_dir + '.json')
if not actor_json:
continue
actor = actor_json['id']
avatarUrl = ''
avatar_url = ''
ext = ''
if actor_json.get('icon'):
if actor_json['icon'].get('url'):
avatarUrl = actor_json['icon']['url']
if '.' in avatarUrl:
ext = '.' + avatarUrl.split('.')[-1]
acctUrl = \
avatar_url = actor_json['icon']['url']
if '.' in avatar_url:
ext = '.' + avatar_url.split('.')[-1]
acct_url = \
'/users/' + nickname + '?options=' + actor + ';1;' + \
'/members/' + acctNickname + ext
infoForm += '<td>\n<a href="' + acctUrl + '">'
infoForm += '<img loading="lazy" style="width:90%" '
infoForm += 'src="' + avatarUrl + '" />'
infoForm += '<br><center>'
if is_moderator(base_dir, acctNickname):
infoForm += '<b><u>' + acctNickname + '</u></b>'
'/members/' + acct_nickname + ext
info_form += '<td>\n<a href="' + acct_url + '">'
info_form += '<img loading="lazy" style="width:90%" '
info_form += 'src="' + avatar_url + '" />'
info_form += '<br><center>'
if is_moderator(base_dir, acct_nickname):
info_form += '<b><u>' + acct_nickname + '</u></b>'
else:
infoForm += acctNickname
if is_editor(base_dir, acctNickname):
infoForm += ''
infoForm += '</center></a>\n</td>\n'
info_form += acct_nickname
if is_editor(base_dir, acct_nickname):
info_form += ''
info_form += '</center></a>\n</td>\n'
col += 1
if col == cols:
# new row of accounts
infoForm += '</tr>\n<tr>\n'
infoForm += '</tr>\n</table>\n'
infoForm += '</div>\n'
info_form += '</tr>\n<tr>\n'
info_form += '</tr>\n</table>\n'
info_form += '</div>\n'
if len(accounts) > 10:
infoForm += '</details>\n'
info_form += '</details>\n'
suspendedFilename = base_dir + '/accounts/suspended.txt'
if os.path.isfile(suspendedFilename):
with open(suspendedFilename, 'r') as f:
suspendedStr = f.read()
infoForm += '<div class="container">\n'
infoForm += ' <br><b>' + \
suspended_filename = base_dir + '/accounts/suspended.txt'
if os.path.isfile(suspended_filename):
with open(suspended_filename, 'r') as fp_sus:
suspended_str = fp_sus.read()
info_form += '<div class="container">\n'
info_form += ' <br><b>' + \
translate['Suspended accounts'] + '</b>'
infoForm += ' <br>' + \
info_form += ' <br>' + \
translate['These are currently suspended']
infoForm += \
info_form += \
' <textarea id="message" ' + \
'name="suspended" style="height:200px" spellcheck="false">' + \
suspendedStr + '</textarea>\n'
infoForm += '</div>\n'
infoShown = True
suspended_str + '</textarea>\n'
info_form += '</div>\n'
info_shown = True
blockingFilename = base_dir + '/accounts/blocking.txt'
if os.path.isfile(blockingFilename):
with open(blockingFilename, 'r') as f:
blockedStr = f.read()
infoForm += '<div class="container">\n'
infoForm += \
blocking_filename = base_dir + '/accounts/blocking.txt'
if os.path.isfile(blocking_filename):
with open(blocking_filename, 'r') as fp_block:
blocked_str = fp_block.read()
info_form += '<div class="container">\n'
info_form += \
' <br><b>' + \
translate['Blocked accounts and hashtags'] + '</b>'
infoForm += \
info_form += \
' <br>' + \
translate[msgStr1]
infoForm += \
translate[msg_str1]
info_form += \
' <textarea id="message" ' + \
'name="blocked" style="height:700px" spellcheck="false">' + \
blockedStr + '</textarea>\n'
infoForm += '</div>\n'
infoShown = True
blocked_str + '</textarea>\n'
info_form += '</div>\n'
info_shown = True
filtersFilename = base_dir + '/accounts/filters.txt'
if os.path.isfile(filtersFilename):
with open(filtersFilename, 'r') as f:
filteredStr = f.read()
infoForm += '<div class="container">\n'
infoForm += \
filters_filename = base_dir + '/accounts/filters.txt'
if os.path.isfile(filters_filename):
with open(filters_filename, 'r') as fp_filt:
filtered_str = fp_filt.read()
info_form += '<div class="container">\n'
info_form += \
' <br><b>' + \
translate['Filtered words'] + '</b>'
infoForm += \
info_form += \
' <textarea id="message" ' + \
'name="filtered" style="height:700px" spellcheck="true">' + \
filteredStr + '</textarea>\n'
infoForm += '</div>\n'
infoShown = True
filtered_str + '</textarea>\n'
info_form += '</div>\n'
info_shown = True
if not infoShown:
infoForm += \
if not info_shown:
info_form += \
'<center><p>' + \
translate[msgStr2] + \
translate[msg_str2] + \
'</p></center>\n'
infoForm += html_footer()
return infoForm
info_form += html_footer()
return info_form