From 865c316254cc18ca42c64c2aa8bbbd304e5336fb Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 30 May 2022 16:15:17 +0100 Subject: [PATCH 1/5] Tidying --- maps.py | 8 ++++---- metadata.py | 8 ++++---- newsdaemon.py | 5 ++--- newswire.py | 14 ++++++-------- pgp.py | 4 ++-- posts.py | 16 +++++++++------- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/maps.py b/maps.py index c4ecac990..a7f224110 100644 --- a/maps.py +++ b/maps.py @@ -202,13 +202,13 @@ def geocoords_from_map_link(url: str, """ if osm_domain in url: return _geocoords_from_osm_link(url, osm_domain) - elif '.google.co' in url: + if '.google.co' in url: return _geocoords_from_gmaps_link(url) - elif '.bing.co' in url: + if '.bing.co' in url: return _geocoords_from_bmaps_link(url) - elif '.waze.co' in url: + if '.waze.co' in url: return _geocoords_from_waze_link(url) - elif 'wego.here.co' in url: + if 'wego.here.co' in url: return _geocoords_from_wego_link(url) return None, None, None diff --git a/metadata.py b/metadata.py index 40c9fb088..d3d488a12 100644 --- a/metadata.py +++ b/metadata.py @@ -35,7 +35,7 @@ def meta_data_node_info(base_dir: str, about_url: str, terms_of_service_url: str, registration: bool, version: str, - showAccounts: bool) -> {}: + show_accounts: bool) -> {}: """ /nodeinfo/2.0 endpoint Also see https://socialhub.activitypub.rocks/t/ fep-f1d5-nodeinfo-in-fediverse-software/1190/4 @@ -46,7 +46,7 @@ def meta_data_node_info(base_dir: str, Also exposure of the version number and number of accounts could be sensitive """ - if showAccounts: + if show_accounts: active_accounts = no_of_accounts(base_dir) active_accounts_monthly = no_of_active_accounts_monthly(base_dir, 1) active_accounts_half_year = no_of_active_accounts_monthly(base_dir, 6) @@ -81,7 +81,7 @@ def meta_data_node_info(base_dir: str, return nodeinfo -def meta_data_instance(showAccounts: bool, +def meta_data_instance(show_accounts: bool, instance_title: str, instance_description_short: str, instance_description: str, @@ -131,7 +131,7 @@ def meta_data_instance(showAccounts: bool, http_prefix + '://' + domain_full + '/@' + \ admin_actor['preferredUsername'] - if showAccounts: + if show_accounts: active_accounts = no_of_accounts(base_dir) local_posts = _get_status_count(base_dir) else: diff --git a/newsdaemon.py b/newsdaemon.py index 431230ccc..0faf24a00 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -54,7 +54,7 @@ def _update_feeds_outbox_index(base_dir: str, domain: str, feeds_file.seek(0, 0) feeds_file.write(post_id + '\n' + content) print('DEBUG: feeds post added to index') - except BaseException as ex: + except OSError as ex: print('EX: Failed to write entry to feeds posts index ' + index_filename + ' ' + str(ex)) else: @@ -803,8 +803,7 @@ def run_newswire_daemon(base_dir: str, httpd, print('Newswire daemon has no session') time.sleep(60) continue - else: - print('Newswire daemon session established') + print('Newswire daemon session established') # try to update the feeds print('Updating newswire feeds') diff --git a/newswire.py b/newswire.py index db20b0956..8acd22364 100644 --- a/newswire.py +++ b/newswire.py @@ -471,7 +471,7 @@ def _valid_podcast_entry(base_dir: str, key: str, entry: {}) -> bool: https://github.com/Podcastindex-org/podcast-namespace/ blob/main/proposal-docs/social/social.md#socialinteract-element """ - if key == 'socialInteract' or key == 'discussion': + if key in ('socialInteract', 'discussion'): if not entry.get('protocol'): return False if not entry.get('uri'): @@ -678,10 +678,9 @@ def get_link_from_rss_item(rss_item: str, '.i2p/' not in link: continue return link, mime_type - else: - if '.onion/' not in link and \ - '.i2p/' not in link: - return link, mime_type + if '.onion/' not in link and \ + '.i2p/' not in link: + return link, mime_type if ' None: property_found = property_value break if property_found: - actor_json['attachment'].remove(property_value) + actor_json['attachment'].remove(property_found) if remove_key: return @@ -283,7 +283,7 @@ def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None: property_found = property_value break if property_found: - actor_json['attachment'].remove(property_value) + actor_json['attachment'].remove(property_found) if remove_fingerprint: return diff --git a/posts.py b/posts.py index c102b29b0..d8fe82f0d 100644 --- a/posts.py +++ b/posts.py @@ -1451,7 +1451,7 @@ def _create_post_base(base_dir: str, break if music_metadata: for audio_tag, audio_value in music_metadata.items(): - if audio_tag == 'title' or audio_tag == 'track': + if audio_tag in ('title', 'track'): continue # capitalize and remove any spaces audio_value = audio_value.title().replace(' ', '') @@ -1984,7 +1984,7 @@ def create_question_post(base_dir: str, client_to_server: bool, comments_enabled: bool, attach_image_filename: str, media_type: str, image_description: str, city: str, - subject: str, durationDays: int, + subject: str, duration_days: int, system_language: str, low_bandwidth: bool, content_license_url: str, languages_understood: []) -> {}: @@ -2011,7 +2011,7 @@ def create_question_post(base_dir: str, message_json['object']['votersCount'] = 0 curr_time = datetime.datetime.utcnow() days_since_epoch = \ - int((curr_time - datetime.datetime(1970, 1, 1)).days + durationDays) + int((curr_time - datetime.datetime(1970, 1, 1)).days + duration_days) end_time = datetime.datetime(1970, 1, 1) + \ datetime.timedelta(days_since_epoch) message_json['object']['endTime'] = end_time.strftime("%Y-%m-%dT%H:%M:%SZ") @@ -2559,7 +2559,7 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str, from_nickname: str, password: str, from_domain: str, from_port: int, to_nickname: str, to_domain: str, to_port: int, - cc: str, + cc_str: str, http_prefix: str, content: str, followers_only: bool, comments_enabled: bool, attach_image_filename: str, media_type: str, @@ -2631,7 +2631,8 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str, client_to_server = True if to_domain.lower().endswith('public'): to_person_id = 'https://www.w3.org/ns/activitystreams#Public' - cc = local_actor_url(http_prefix, from_nickname, from_domain_full) + \ + cc_str = \ + local_actor_url(http_prefix, from_nickname, from_domain_full) + \ '/followers' else: if to_domain.lower().endswith('followers') or \ @@ -2648,7 +2649,7 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str, post_json_object = \ _create_post_base(base_dir, from_nickname, from_domain, from_port, - to_person_id, cc, http_prefix, content, + to_person_id, cc_str, http_prefix, content, followers_only, save_to_file, client_to_server, comments_enabled, attach_image_filename, media_type, @@ -2760,7 +2761,8 @@ def _add_followers_to_public_post(post_json_object: {}) -> None: def send_signed_json(post_json_object: {}, session, base_dir: str, nickname: str, domain: str, port: int, - to_nickname: str, to_domain: str, to_port: int, cc: str, + to_nickname: str, to_domain: str, + to_port: int, cc_str: str, http_prefix: str, save_to_file: bool, client_to_server: bool, federation_list: [], send_threads: [], post_log: [], cached_webfingers: {}, From 967cd84ce7c873caabfebbd9106af70e01f51eb3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 30 May 2022 19:33:51 +0100 Subject: [PATCH 2/5] Tidying --- languages.py | 19 ++++--- like.py | 9 ++-- linked_data_sig.py | 4 +- webapp_column_left.py | 8 +-- webapp_headerbuttons.py | 6 +-- webapp_likers.py | 4 +- webapp_podcast.py | 2 +- webapp_post.py | 16 +++--- webapp_profile.py | 41 ++++++++------- webapp_question.py | 62 +++++++++++----------- webapp_search.py | 110 ++++++++++++++++++++------------------- webapp_theme_designer.py | 7 +-- 12 files changed, 145 insertions(+), 143 deletions(-) diff --git a/languages.py b/languages.py index 16f59742c..d586f96e9 100644 --- a/languages.py +++ b/languages.py @@ -153,7 +153,7 @@ def libretranslate_languages(url: str, api_key: str = None) -> []: else: url += "languages" - params = dict() + params = {} if api_key: params["api_key"] = api_key @@ -162,9 +162,9 @@ def libretranslate_languages(url: str, api_key: str = None) -> []: req = request.Request(url, data=url_params.encode()) - response = request.urlopen(req) - - response_str = response.read().decode() + response_str = '' + with request.urlopen(req) as response: + response_str = response.read().decode() result = json.loads(response_str) if not result: @@ -270,13 +270,16 @@ def libretranslate(url: str, text: str, url_params = parse.urlencode(lt_params) req = request.Request(url, data=url_params.encode()) + response_str = None try: - response = request.urlopen(req) - except BaseException: - print('EX: Unable to translate: ' + text) + with request.urlopen(req) as response: + response_str = response.read().decode() + except BaseException as ex: + print('EX: Unable to translate: ' + text + ' ' + str(ex)) return original_text - response_str = response.read().decode() + if not response_str: + return original_text translated_text = \ '

' + json.loads(response_str)['translatedText'] + '

' diff --git a/like.py b/like.py index 425d20c6c..51a2b00cb 100644 --- a/like.py +++ b/like.py @@ -74,7 +74,7 @@ def _create_like(recent_posts_cache: {}, cc_list: [], http_prefix: str, object_url: str, actor_liked: str, client_to_server: bool, - send_threads: [], postLog: [], + send_threads: [], post_log: [], person_cache: {}, cached_webfingers: {}, debug: bool, project_version: str, signing_priv_key_pem: str, @@ -141,7 +141,7 @@ def _create_like(recent_posts_cache: {}, liked_post_port, 'https://www.w3.org/ns/activitystreams#Public', http_prefix, True, client_to_server, federation_list, - send_threads, postLog, cached_webfingers, + send_threads, post_log, cached_webfingers, person_cache, debug, project_version, None, group_account, signing_priv_key_pem, 7367374, @@ -156,7 +156,7 @@ def like_post(recent_posts_cache: {}, like_nickname: str, like_domain: str, like_port: int, cc_list: [], like_status_number: int, client_to_server: bool, - send_threads: [], postLog: [], + send_threads: [], post_log: [], person_cache: {}, cached_webfingers: {}, debug: bool, project_version: str, signing_priv_key_pem: str, @@ -173,7 +173,8 @@ def like_post(recent_posts_cache: {}, nickname, domain, port, cc_list, http_prefix, object_url, actor_liked, client_to_server, - send_threads, postLog, person_cache, cached_webfingers, + send_threads, post_log, person_cache, + cached_webfingers, debug, project_version, signing_priv_key_pem, curr_domain, onion_domain, i2p_domain) diff --git a/linked_data_sig.py b/linked_data_sig.py index a2790fc81..3c61d24c3 100644 --- a/linked_data_sig.py +++ b/linked_data_sig.py @@ -87,8 +87,8 @@ def verify_json_signature(doc: {}, public_key_pem: str) -> bool: padding.PKCS1v15(), hazutils.Prehashed(hashes.SHA256())) return True - except BaseException: - print('EX: verify_json_signature unable to verify') + except BaseException as ex: + print('EX: verify_json_signature unable to verify ' + str(ex)) return False diff --git a/webapp_column_left.py b/webapp_column_left.py index dc88eec99..97df269e7 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -117,7 +117,7 @@ def _get_left_column_wanted(base_dir: str, def get_left_column_content(base_dir: str, nickname: str, domain_full: str, http_prefix: str, translate: {}, editor: bool, artist: bool, - show_back_button: bool, timelinePath: str, + show_back_button: bool, timeline_path: str, rss_icon_at_top: bool, show_header_image: bool, front_page: bool, theme: str, access_keys: {}, @@ -146,7 +146,7 @@ def get_left_column_content(base_dir: str, nickname: str, domain_full: str, if show_back_button: html_str += \ - '
' + \ + '
' + \ '\n' @@ -359,7 +359,7 @@ def get_left_column_content(base_dir: str, nickname: str, domain_full: str, def html_links_mobile(css_cache: {}, base_dir: str, nickname: str, domain_full: str, http_prefix: str, translate, - timelinePath: str, authorized: bool, + timeline_path: str, authorized: bool, rss_icon_at_top: bool, icons_as_buttons: bool, default_timeline: str, @@ -406,7 +406,7 @@ def html_links_mobile(css_cache: {}, base_dir: str, get_left_column_content(base_dir, nickname, domain_full, http_prefix, translate, editor, artist, - False, timelinePath, + False, timeline_path, rss_icon_at_top, False, False, theme, access_keys, shared_items_federated_domains) diff --git a/webapp_headerbuttons.py b/webapp_headerbuttons.py index 5b38b1bcc..14670319f 100644 --- a/webapp_headerbuttons.py +++ b/webapp_headerbuttons.py @@ -22,7 +22,7 @@ def header_buttons_timeline(default_timeline: str, page_number: int, translate: {}, users_path: str, - mediaButton: str, + media_button: str, blogs_button: str, features_button: str, news_button: str, @@ -62,7 +62,7 @@ def header_buttons_timeline(default_timeline: str, tl_str += ' aria-current="location"' tl_str += \ '>' elif default_timeline == 'tlblogs': tl_str += \ @@ -134,7 +134,7 @@ def header_buttons_timeline(default_timeline: str, tl_str += ' aria-current="location"' tl_str += \ '>' else: if not minimal: diff --git a/webapp_likers.py b/webapp_likers.py index 54d51507a..15d024b88 100644 --- a/webapp_likers.py +++ b/webapp_likers.py @@ -40,7 +40,7 @@ def html_likers_of_post(base_dir: str, nickname: str, system_language: str, max_like_count: int, signing_priv_key_pem: str, cw_lists: {}, lists_enabled: str, - boxName: str, default_timeline: str, + box_name: str, default_timeline: str, bold_reading: bool, dict_name: str = 'likes') -> str: """Returns html for a screen showing who liked a post @@ -96,7 +96,7 @@ def html_likers_of_post(base_dir: str, nickname: str, None, True, False, http_prefix, project_version, - boxName, + box_name, yt_replace_domain, twitter_replacement_domain, show_published_date_only, diff --git a/webapp_podcast.py b/webapp_podcast.py index 732e252c9..b570c6b2c 100644 --- a/webapp_podcast.py +++ b/webapp_podcast.py @@ -118,7 +118,7 @@ def _html_podcast_transcripts(podcast_properties: {}, translate: {}) -> str: return '' ctr = 1 html_str = '' - for transcript in podcast_properties[key]: + for _ in podcast_properties[key]: transcript_url = None if podcast_properties[key].get('url'): transcript_url = podcast_properties[key]['url'] diff --git a/webapp_post.py b/webapp_post.py index 92dd236b0..29838ad40 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -214,14 +214,14 @@ def _html_post_metadata_open_graph(domain: str, post_json_object: {}, def _log_post_timing(enable_timing_log: bool, post_start_time, - debugId: str) -> None: + debug_id: str) -> None: """Create a log of timings for performance tuning """ if not enable_timing_log: return time_diff = int((time.time() - post_start_time) * 1000) if time_diff > 100: - print('TIMING INDIV ' + debugId + ' = ' + str(time_diff)) + print('TIMING INDIV ' + debug_id + ' = ' + str(time_diff)) def prepare_html_post_nickname(nickname: str, post_html: str) -> str: @@ -374,7 +374,7 @@ def _get_post_from_recent_cache(session, return post_html -def _get_avatar_image_html(showAvatarOptions: bool, +def _get_avatar_image_html(show_avatar_options: bool, nickname: str, domain_full: str, avatar_url: str, post_actor: str, translate: {}, avatar_position: str, @@ -399,7 +399,7 @@ def _get_avatar_image_html(showAvatarOptions: bool, show_profile_str + '" alt=" "' + avatar_position + \ get_broken_link_substitute() + '/>\n' - if showAvatarOptions and \ + if show_avatar_options and \ domain_full + '/users/' + nickname not in post_actor: show_options_for_this_person_str = 'Show options for this person' if translate.get(show_options_for_this_person_str): @@ -528,7 +528,7 @@ def _get_reply_icon_html(base_dir: str, nickname: str, domain: str, def _get_edit_icon_html(base_dir: str, nickname: str, domain_full: str, post_json_object: {}, actor_nickname: str, - translate: {}, isEvent: bool) -> str: + translate: {}, is_event: bool) -> str: """Returns html for the edit icon/button """ edit_str = '' @@ -573,7 +573,7 @@ def _get_edit_icon_html(base_dir: str, nickname: str, domain_full: str, '' + edit_blog_post_str + \
                     ' |\n' - elif isEvent: + elif is_event: edit_event_str = 'Edit event' if translate.get(edit_event_str): edit_event_str = translate[edit_event_str] @@ -1488,7 +1488,7 @@ def individual_post_as_html(signing_priv_key_pem: str, session, cached_webfingers: {}, person_cache: {}, nickname: str, domain: str, port: int, post_json_object: {}, - avatar_url: str, showAvatarOptions: bool, + avatar_url: str, show_avatar_options: bool, allow_deletion: bool, http_prefix: str, project_version: str, box_name: str, @@ -1642,7 +1642,7 @@ def individual_post_as_html(signing_priv_key_pem: str, _log_post_timing(enable_timing_log, post_start_time, '7') avatar_link = \ - _get_avatar_image_html(showAvatarOptions, + _get_avatar_image_html(show_avatar_options, nickname, domain_full, avatar_url, post_actor, translate, avatar_position, diff --git a/webapp_profile.py b/webapp_profile.py index f49198761..453a75673 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -613,7 +613,7 @@ def html_profile(signing_priv_key_pem: str, debug: bool, access_keys: {}, city: str, system_language: str, max_like_count: int, shared_items_federated_domains: [], - extraJson: {}, page_number: int, + extra_json: {}, page_number: int, max_items_per_page: int, cw_lists: {}, lists_enabled: str, content_license_url: str, @@ -636,7 +636,7 @@ def html_profile(signing_priv_key_pem: str, yt_replace_domain, twitter_replacement_domain, show_published_date_only, - newswire, theme, extraJson, + newswire, theme, extra_json, allow_local_network_access, access_keys, system_language, max_like_count, shared_items_federated_domains, None, @@ -1042,7 +1042,7 @@ def html_profile(signing_priv_key_pem: str, authorized, nickname, domain, port, session, cached_webfingers, - person_cache, extraJson, + person_cache, extra_json, project_version, ["unfollow"], selected, users_path, page_number, @@ -1055,7 +1055,7 @@ def html_profile(signing_priv_key_pem: str, authorized, nickname, domain, port, session, cached_webfingers, - person_cache, extraJson, + person_cache, extra_json, project_version, ["block"], selected, users_path, page_number, max_items_per_page, dormant_months, debug, @@ -1064,21 +1064,21 @@ def html_profile(signing_priv_key_pem: str, if selected == 'roles': profile_str += \ _html_profile_roles(translate, nickname, domain_full, - extraJson) + extra_json) elif selected == 'skills': profile_str += \ _html_profile_skills(translate, nickname, domain_full, - extraJson) + extra_json) # elif selected == 'shares': # profile_str += \ # _html_profile_shares(actor, translate, # nickname, domain_full, -# extraJson, 'shares') + license_str +# extra_json, 'shares') + license_str # elif selected == 'wanted': # profile_str += \ # _html_profile_shares(actor, translate, # nickname, domain_full, -# extraJson, 'wanted') + license_str +# extra_json, 'wanted') + license_str # end of #timeline profile_str += '
' @@ -1232,13 +1232,13 @@ def _html_profile_following(translate: {}, base_dir: str, http_prefix: str, def _html_profile_roles(translate: {}, nickname: str, domain: str, - rolesList: []) -> str: + roles_list: []) -> str: """Shows roles on the profile screen """ profile_str = '' profile_str += \ '
\n
\n' - for role in rolesList: + for role in roles_list: if translate.get(role): profile_str += '

' + translate[role] + '

\n' else: @@ -2462,7 +2462,7 @@ def _individual_follow_as_html(signing_priv_key_pem: str, base_dir: str, session, cached_webfingers: {}, person_cache: {}, domain: str, - followUrl: str, + follow_url: str, authorized: bool, actor_nickname: str, http_prefix: str, @@ -2472,21 +2472,22 @@ def _individual_follow_as_html(signing_priv_key_pem: str, buttons=[]) -> str: """An individual follow entry on the profile screen """ - follow_url_nickname = get_nickname_from_actor(followUrl) + follow_url_nickname = get_nickname_from_actor(follow_url) if not follow_url_nickname: return '' - follow_url_domain, follow_url_port = get_domain_from_actor(followUrl) + follow_url_domain, follow_url_port = get_domain_from_actor(follow_url) follow_url_domain_full = \ get_full_domain(follow_url_domain, follow_url_port) title_str = '@' + follow_url_nickname + '@' + follow_url_domain_full - avatar_url = get_person_avatar_url(base_dir, followUrl, person_cache, True) + avatar_url = \ + get_person_avatar_url(base_dir, follow_url, person_cache, True) if not avatar_url: - avatar_url = followUrl + '/avatar.png' + avatar_url = follow_url + '/avatar.png' - display_name = get_display_name(base_dir, followUrl, person_cache) + display_name = get_display_name(base_dir, follow_url, person_cache) is_group = False if not display_name: - # lookup the correct webfinger for the followUrl + # lookup the correct webfinger for the follow_url follow_url_handle = follow_url_nickname + '@' + follow_url_domain_full follow_url_wf = \ webfinger_handle(session, follow_url_handle, http_prefix, @@ -2524,7 +2525,7 @@ def _individual_follow_as_html(signing_priv_key_pem: str, if btn == 'block': buttons_str += \ '\n' @@ -2536,7 +2537,7 @@ def _individual_follow_as_html(signing_priv_key_pem: str, unfollow_str = 'Leave' buttons_str += \ '\n' @@ -2544,7 +2545,7 @@ def _individual_follow_as_html(signing_priv_key_pem: str, result_str = '
\n' result_str += \ '\n' + follow_url + ';1;' + avatar_url + '">\n' result_str += '

 ' result_str += title_str + '' + buttons_str + '

\n' diff --git a/webapp_question.py b/webapp_question.py index fe2881d4f..b6b3cfcaa 100644 --- a/webapp_question.py +++ b/webapp_question.py @@ -16,37 +16,37 @@ from utils import acct_dir def insert_question(base_dir: str, translate: {}, nickname: str, domain: str, port: int, content: str, - post_json_object: {}, pageNumber: int) -> str: + post_json_object: {}, page_number: int) -> str: """ Inserts question selection into a post """ if not is_question(post_json_object): return content if len(post_json_object['object']['oneOf']) == 0: return content - messageId = remove_id_ending(post_json_object['id']) - if '#' in messageId: - messageId = messageId.split('#', 1)[0] - pageNumberStr = '' - if pageNumber: - pageNumberStr = '?page=' + str(pageNumber) + message_id = remove_id_ending(post_json_object['id']) + if '#' in message_id: + message_id = message_id.split('#', 1)[0] + page_number_str = '' + if page_number: + page_number_str = '?page=' + str(page_number) - votesFilename = \ + votes_filename = \ acct_dir(base_dir, nickname, domain) + '/questions.txt' - showQuestionResults = False - if os.path.isfile(votesFilename): - if messageId in open(votesFilename).read(): - showQuestionResults = True + show_question_results = False + if os.path.isfile(votes_filename): + if message_id in open(votes_filename).read(): + show_question_results = True - if not showQuestionResults: + if not show_question_results: # show the question options content += '
' content += \ '
\n' + nickname + '/question' + page_number_str + '">\n' content += \ '\n
\n' + message_id + '">\n
\n' for choice in post_json_object['object']['oneOf']: if not choice.get('type'): continue @@ -64,45 +64,43 @@ def insert_question(base_dir: str, translate: {}, content += '
\n' # get the maximum number of votes - maxVotes = 1 - for questionOption in post_json_object['object']['oneOf']: - if not questionOption.get('name'): + max_votes = 1 + for question_option in post_json_object['object']['oneOf']: + if not question_option.get('name'): continue - if not questionOption.get('replies'): + if not question_option.get('replies'): continue votes = 0 try: - votes = int(questionOption['replies']['totalItems']) + votes = int(question_option['replies']['totalItems']) except BaseException: print('EX: insert_question unable to convert to int') - if votes > maxVotes: - maxVotes = int(votes+1) + if votes > max_votes: + max_votes = int(votes+1) # show the votes as sliders - questionCtr = 1 - for questionOption in post_json_object['object']['oneOf']: - if not questionOption.get('name'): + for question_option in post_json_object['object']['oneOf']: + if not question_option.get('name'): continue - if not questionOption.get('replies'): + if not question_option.get('replies'): continue votes = 0 try: - votes = int(questionOption['replies']['totalItems']) + votes = int(question_option['replies']['totalItems']) except BaseException: print('EX: insert_question unable to convert to int 2') - votesPercent = str(int(votes * 100 / maxVotes)) + votes_percent = str(int(votes * 100 / max_votes)) content += \ '

\n' + \ '
\n' + \ + question_option['name'] + '
\n' + \ ' \n' + \ - ' \n' + \ ' ' + \ - ' \n' + \ + ' \n' + \ '

\n' - questionCtr += 1 content += '
\n' return content diff --git a/webapp_search.py b/webapp_search.py index d7888044f..dfea4f615 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -490,30 +490,31 @@ def html_skills_search(actor: str, continue actor_filename = os.path.join(subdir, fname) actor_json = load_json(actor_filename) - if actor_json: - if actor_json.get('id') and \ - no_of_actor_skills(actor_json) > 0 and \ - actor_json.get('name') and \ - actor_json.get('icon'): - actor = actor_json['id'] - actor_skills_list = actor_json['hasOccupation']['skills'] - skills = get_skills_from_list(actor_skills_list) - for skill_name, skill_level in skills.items(): - skill_name = skill_name.lower() - if not (skill_name in skillsearch or - skillsearch in skill_name): - continue - skill_level_str = str(skill_level) - if skill_level < 100: - skill_level_str = '0' + skill_level_str - if skill_level < 10: - skill_level_str = '0' + skill_level_str - index_str = \ - skill_level_str + ';' + actor + ';' + \ - actor_json['name'] + \ - ';' + actor_json['icon']['url'] - if index_str not in results: - results.append(index_str) + if not actor_json: + continue + if actor_json.get('id') and \ + no_of_actor_skills(actor_json) > 0 and \ + actor_json.get('name') and \ + actor_json.get('icon'): + actor = actor_json['id'] + actor_skills_list = actor_json['hasOccupation']['skills'] + skills = get_skills_from_list(actor_skills_list) + for skill_name, skill_level in skills.items(): + skill_name = skill_name.lower() + if not (skill_name in skillsearch or + skillsearch in skill_name): + continue + skill_level_str = str(skill_level) + if skill_level < 100: + skill_level_str = '0' + skill_level_str + if skill_level < 10: + skill_level_str = '0' + skill_level_str + index_str = \ + skill_level_str + ';' + actor + ';' + \ + actor_json['name'] + \ + ';' + actor_json['icon']['url'] + if index_str not in results: + results.append(index_str) break if not instance_only: # search actor cache @@ -525,33 +526,34 @@ def html_skills_search(actor: str, continue actor_filename = os.path.join(subdir, fname) cached_actor_json = load_json(actor_filename) - if cached_actor_json: - if cached_actor_json.get('actor'): - actor_json = cached_actor_json['actor'] - if actor_json.get('id') and \ - no_of_actor_skills(actor_json) > 0 and \ - actor_json.get('name') and \ - actor_json.get('icon'): - actor = actor_json['id'] - actor_skills_list = \ - actor_json['hasOccupation']['skills'] - skills = get_skills_from_list(actor_skills_list) - for skill_name, skill_level in skills.items(): - skill_name = skill_name.lower() - if not (skill_name in skillsearch or - skillsearch in skill_name): - continue - skill_level_str = str(skill_level) - if skill_level < 100: - skill_level_str = '0' + skill_level_str - if skill_level < 10: - skill_level_str = '0' + skill_level_str - index_str = \ - skill_level_str + ';' + actor + ';' + \ - actor_json['name'] + \ - ';' + actor_json['icon']['url'] - if index_str not in results: - results.append(index_str) + if not cached_actor_json: + continue + if cached_actor_json.get('actor'): + actor_json = cached_actor_json['actor'] + if actor_json.get('id') and \ + no_of_actor_skills(actor_json) > 0 and \ + actor_json.get('name') and \ + actor_json.get('icon'): + actor = actor_json['id'] + actor_skills_list = \ + actor_json['hasOccupation']['skills'] + skills = get_skills_from_list(actor_skills_list) + for skill_name, skill_level in skills.items(): + skill_name = skill_name.lower() + if not (skill_name in skillsearch or + skillsearch in skill_name): + continue + skill_level_str = str(skill_level) + if skill_level < 100: + skill_level_str = '0' + skill_level_str + if skill_level < 10: + skill_level_str = '0' + skill_level_str + index_str = \ + skill_level_str + ';' + actor + ';' + \ + actor_json['name'] + \ + ';' + actor_json['icon']['url'] + if index_str not in results: + results.append(index_str) break results.sort(reverse=True) @@ -616,7 +618,7 @@ def html_history_search(css_cache: {}, translate: {}, base_dir: str, show_published_date_only: bool, peertube_instances: [], allow_local_network_access: bool, - theme_name: str, boxName: str, + theme_name: str, box_name: str, system_language: str, max_like_count: int, signing_priv_key_pem: str, @@ -632,7 +634,7 @@ def html_history_search(css_cache: {}, translate: {}, base_dir: str, box_filenames = \ search_box_posts(base_dir, nickname, domain, - historysearch, posts_per_page, boxName) + historysearch, posts_per_page, box_name) css_filename = base_dir + '/epicyon-profile.css' if os.path.isfile(base_dir + '/epicyon.css'): @@ -647,7 +649,7 @@ def html_history_search(css_cache: {}, translate: {}, base_dir: str, domain_full = get_full_domain(domain, port) actor = local_actor_url(http_prefix, nickname, domain_full) history_search_title = '🔍 ' + translate['Your Posts'] - if boxName == 'bookmarks': + if box_name == 'bookmarks': history_search_title = '🔍 ' + translate['Bookmarks'] history_search_form += \ diff --git a/webapp_theme_designer.py b/webapp_theme_designer.py index f3e8d5e3f..8ba236699 100644 --- a/webapp_theme_designer.py +++ b/webapp_theme_designer.py @@ -255,8 +255,7 @@ def html_theme_designer(css_cache: {}, base_dir: str, variable_name_str = variable_name_str.title() variable_name_label = variable_name_str if contrast_warning: - if variable_name == 'main-bg-color' or \ - variable_name == 'main-fg-color': + if variable_name in ('main-bg-color', 'main-fg-color'): variable_name_label = contrast_warning + variable_name_str font_str += \ '