Snake case

merge-requests/26/head
Bob Mottram 2022-01-02 12:38:22 +00:00
parent b962b267a0
commit ca4931daa4
1 changed files with 45 additions and 45 deletions

View File

@ -14,7 +14,7 @@ def _get_donation_types() -> []:
'subscribestar') 'subscribestar')
def _get_websiteStrings() -> []: def _get_website_strings() -> []:
return ['www', 'website', 'web', 'homepage'] return ['www', 'website', 'web', 'homepage']
@ -23,11 +23,11 @@ def get_donation_url(actor_json: {}) -> str:
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
donationType = _get_donation_types() donation_type = _get_donation_types()
for property_value in actor_json['attachment']: for property_value in actor_json['attachment']:
if not property_value.get('name'): if not property_value.get('name'):
continue continue
if property_value['name'].lower() not in donationType: if property_value['name'].lower() not in donation_type:
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
@ -48,12 +48,12 @@ def get_website(actor_json: {}, translate: {}) -> str:
""" """
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
return '' return ''
matchStrings = _get_websiteStrings() match_strings = _get_website_strings()
matchStrings.append(translate['Website'].lower()) match_strings.append(translate['Website'].lower())
for property_value in actor_json['attachment']: for property_value in actor_json['attachment']:
if not property_value.get('name'): if not property_value.get('name'):
continue continue
if property_value['name'].lower() not in matchStrings: if property_value['name'].lower() not in match_strings:
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
@ -68,44 +68,44 @@ def get_website(actor_json: {}, translate: {}) -> str:
def set_donation_url(actor_json: {}, donate_url: str) -> None: def set_donation_url(actor_json: {}, donate_url: str) -> None:
"""Sets a link used for donations """Sets a link used for donations
""" """
notUrl = False not_url = False
if '.' not in donate_url: if '.' not in donate_url:
notUrl = True not_url = True
if '://' not in donate_url: if '://' not in donate_url:
notUrl = True not_url = True
if ' ' in donate_url: if ' ' in donate_url:
notUrl = True not_url = True
if '<' in donate_url: if '<' in donate_url:
notUrl = True not_url = True
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
actor_json['attachment'] = [] actor_json['attachment'] = []
donationType = _get_donation_types() donation_type = _get_donation_types()
donateName = None donate_name = None
for paymentService in donationType: for payment_service in donation_type:
if paymentService in donate_url: if payment_service in donate_url:
donateName = paymentService donate_name = payment_service
if not donateName: if not donate_name:
return return
# remove any existing value # remove any existing value
propertyFound = None property_found = None
for property_value in actor_json['attachment']: for property_value in actor_json['attachment']:
if not property_value.get('name'): if not property_value.get('name'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if not property_value['name'].lower() != donateName: if not property_value['name'].lower() != donate_name:
continue continue
propertyFound = property_value property_found = property_value
break break
if propertyFound: if property_found:
actor_json['attachment'].remove(propertyFound) actor_json['attachment'].remove(property_found)
if notUrl: if not_url:
return return
donateValue = \ donate_value = \
'<a href="' + donate_url + \ '<a href="' + donate_url + \
'" rel="me nofollow noopener noreferrer" target="_blank">' + \ '" rel="me nofollow noopener noreferrer" target="_blank">' + \
donate_url + '</a>' donate_url + '</a>'
@ -115,60 +115,60 @@ def set_donation_url(actor_json: {}, donate_url: str) -> None:
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if property_value['name'].lower() != donateName: if property_value['name'].lower() != donate_name:
continue continue
if property_value['type'] != 'PropertyValue': if property_value['type'] != 'PropertyValue':
continue continue
property_value['value'] = donateValue property_value['value'] = donate_value
return return
newDonate = { new_donate = {
"name": donateName, "name": donate_name,
"type": "PropertyValue", "type": "PropertyValue",
"value": donateValue "value": donate_value
} }
actor_json['attachment'].append(newDonate) actor_json['attachment'].append(new_donate)
def set_website(actor_json: {}, website_url: str, translate: {}) -> None: def set_website(actor_json: {}, website_url: str, translate: {}) -> None:
"""Sets a web address """Sets a web address
""" """
website_url = website_url.strip() website_url = website_url.strip()
notUrl = False not_url = False
if '.' not in website_url: if '.' not in website_url:
notUrl = True not_url = True
if '://' not in website_url: if '://' not in website_url:
notUrl = True not_url = True
if ' ' in website_url: if ' ' in website_url:
notUrl = True not_url = True
if '<' in website_url: if '<' in website_url:
notUrl = True not_url = True
if not actor_json.get('attachment'): if not actor_json.get('attachment'):
actor_json['attachment'] = [] actor_json['attachment'] = []
matchStrings = _get_websiteStrings() match_strings = _get_website_strings()
matchStrings.append(translate['Website'].lower()) match_strings.append(translate['Website'].lower())
# remove any existing value # remove any existing value
propertyFound = None property_found = None
for property_value in actor_json['attachment']: for property_value in actor_json['attachment']:
if not property_value.get('name'): if not property_value.get('name'):
continue continue
if not property_value.get('type'): if not property_value.get('type'):
continue continue
if property_value['name'].lower() not in matchStrings: if property_value['name'].lower() not in match_strings:
continue continue
propertyFound = property_value property_found = property_value
break break
if propertyFound: if property_found:
actor_json['attachment'].remove(propertyFound) actor_json['attachment'].remove(property_found)
if notUrl: if not_url:
return return
newEntry = { new_entry = {
"name": 'Website', "name": 'Website',
"type": "PropertyValue", "type": "PropertyValue",
"value": website_url "value": website_url
} }
actor_json['attachment'].append(newEntry) actor_json['attachment'].append(new_entry)