main
Bob Mottram 2022-05-30 16:15:17 +01:00
parent 69efdba68f
commit 865c316254
6 changed files with 27 additions and 28 deletions

View File

@ -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

View File

@ -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:

View File

@ -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')

View File

@ -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 '<enclosure ' in rss_item:
# get link from audio or video enclosure
@ -1322,9 +1321,8 @@ def get_rss(base_dir: str, domain: str, session, url: str,
max_categories_feedItem_size_kb,
session, debug,
preferred_podcast_formats)
else:
print('WARN: feed is too large, ' +
'or contains invalid characters: ' + url)
print('WARN: feed is too large, ' +
'or contains invalid characters: ' + url)
else:
print('WARN: no result returned for feed ' + url)
except requests.exceptions.RequestException as ex:

4
pgp.py
View File

@ -220,7 +220,7 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> 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

View File

@ -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: {},