From 347691bddca35b6ceeec809c852596af675854e6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 4 Jan 2022 10:13:28 +0000 Subject: [PATCH] Snake case --- webapp_moderation.py | 421 ++++++++++++++++++++++--------------------- 1 file changed, 213 insertions(+), 208 deletions(-) diff --git a/webapp_moderation.py b/webapp_moderation.py index d106dd33a..38ae5a00e 100644 --- a/webapp_moderation.py +++ b/webapp_moderation.py @@ -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 += \ '

' + \ - translate['Account Information'] + ': ' + searchHandle + '


\n' + translate['Account Information'] + ': ' + search_handle + '
\n' - infoForm += translate[msgStr1] + '


\n' + info_form += translate[msg_str1] + '

\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 += '
\n' - usersPath = '/users/' + nickname + '/accountinfo' + info_form += '
\n' + users_path = '/users/' + nickname + '/accountinfo' ctr = 1 - for postDomain, blockedPostUrls in domainDict.items(): - infoForm += '' + \ - postDomain + ' ' - if is_blocked_domain(base_dir, postDomain): - blockedPostsLinks = '' - urlCtr = 0 - for url in blockedPostUrls: - if urlCtr > 0: - blockedPostsLinks += '
' - blockedPostsLinks += \ + post_domain + ' ' + 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 += '
' + blocked_posts_links += \ '' + \ url + '' - 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 += \ - '' - infoForm += ' ' + \ - blockedPostsHtml + '\n' + blocked_posts_html + '\n' else: - infoForm += \ - '' - if postDomain != domain: - infoForm += '' - infoForm += '\n' - infoForm += '
\n' + info_form += '\n' + info_form += '
\n' - infoForm += '
\n' + info_form += '
\n' - if blockedFollowing: - blockedFollowing.sort() - infoForm += '
\n' - infoForm += '

' + translate['Blocked following'] + '

\n' - infoForm += \ + if blocked_following: + blocked_following.sort() + info_form += '
\n' + info_form += '

' + translate['Blocked following'] + '

\n' + info_form += \ '

' + \ translate['Receives posts from the following accounts'] + \ ':

\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 += '' + \ - followingNickname + '@' + followingDomainFull + \ + following_nickname + '@' + following_domain_full + \ '

\n' - infoForm += '
\n' + info_form += '
\n' - if blockedFollowers: - blockedFollowers.sort() - infoForm += '
\n' - infoForm += '

' + translate['Blocked followers'] + '

\n' - infoForm += \ + if blocked_followers: + blocked_followers.sort() + info_form += '
\n' + info_form += '

' + translate['Blocked followers'] + '

\n' + info_form += \ '

' + \ translate['Sends out posts to the following accounts'] + \ ':

\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 += '' + \ - followerNickname + '@' + followerDomainFull + '

\n' - infoForm += '
\n' + follower_nickname + '@' + \ + follower_domain_full + '

\n' + info_form += '
\n' - if wordFrequency: - maxCount = 1 - for word, count in wordFrequency.items(): - if count > maxCount: - maxCount = count - minimumWordCount = int(maxCount / 2) - if minimumWordCount >= 3: - infoForm += '
\n' - infoForm += '

' + translate['Word frequencies'] + '

\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 += '
\n' + info_form += '

' + translate['Word frequencies'] + '

\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 += '' + word + '' + if count != max_count: + word_swarm += '' + word + '' else: - wordSwarm += '' + word + '' + word_swarm += '' + word + '' ctr += 1 - infoForm += wordSwarm - infoForm += '
\n' + info_form += word_swarm + info_form += '
\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 += \ '

' + \ translate['Moderation Information'] + \ '


' - 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 += '
' + translate['Show Accounts'] - infoForm += '\n' - infoForm += '
\n' - infoForm += '\n' - infoForm += ' \n' + info_form += '
' + translate['Show Accounts'] + info_form += '\n' + info_form += '
\n' + info_form += '
\n' + info_form += ' \n' for col in range(cols): - infoForm += ' \n' - infoForm += ' \n' - infoForm += '\n' + info_form += ' \n' + info_form += ' \n' + info_form += '\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 += '\n' + info_form += acct_nickname + if is_editor(base_dir, acct_nickname): + info_form += ' ✍' + info_form += '\n\n' col += 1 if col == cols: # new row of accounts - infoForm += '\n\n' - infoForm += '\n
\n' - infoForm += '' - infoForm += '
' - if is_moderator(base_dir, acctNickname): - infoForm += '' + acctNickname + '' + '/members/' + acct_nickname + ext + info_form += '
\n' + info_form += '' + info_form += '
' + if is_moderator(base_dir, acct_nickname): + info_form += '' + acct_nickname + '' else: - infoForm += acctNickname - if is_editor(base_dir, acctNickname): - infoForm += ' ✍' - infoForm += '
\n
\n' - infoForm += '
\n' + info_form += '\n\n' + info_form += '\n\n' + info_form += '\n' if len(accounts) > 10: - infoForm += '
\n' + info_form += '\n' - suspendedFilename = base_dir + '/accounts/suspended.txt' - if os.path.isfile(suspendedFilename): - with open(suspendedFilename, 'r') as f: - suspendedStr = f.read() - infoForm += '
\n' - infoForm += '
' + \ + 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 += '
\n' + info_form += '
' + \ translate['Suspended accounts'] + '' - infoForm += '
' + \ + info_form += '
' + \ translate['These are currently suspended'] - infoForm += \ + info_form += \ ' \n' - infoForm += '
\n' - infoShown = True + suspended_str + '\n' + info_form += '
\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 += '
\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 += '
\n' + info_form += \ '
' + \ translate['Blocked accounts and hashtags'] + '' - infoForm += \ + info_form += \ '
' + \ - translate[msgStr1] - infoForm += \ + translate[msg_str1] + info_form += \ ' \n' - infoForm += '
\n' - infoShown = True + blocked_str + '\n' + info_form += '
\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 += '
\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 += '
\n' + info_form += \ '
' + \ translate['Filtered words'] + '' - infoForm += \ + info_form += \ ' \n' - infoForm += '
\n' - infoShown = True + filtered_str + '\n' + info_form += '
\n' + info_shown = True - if not infoShown: - infoForm += \ + if not info_shown: + info_form += \ '

' + \ - translate[msgStr2] + \ + translate[msg_str2] + \ '

\n' - infoForm += html_footer() - return infoForm + info_form += html_footer() + return info_form