flake8 format

main
Bob Mottram 2020-04-03 08:54:53 +00:00
parent dfb1263f1a
commit 9b713efb86
1 changed files with 30 additions and 26 deletions

View File

@ -1,24 +1,24 @@
__filename__="donate.py" __filename__ = "donate.py"
__author__="Bob Mottram" __author__ = "Bob Mottram"
__license__="AGPL3+" __license__ = "AGPL3+"
__version__="1.1.0" __version__ = "1.1.0"
__maintainer__="Bob Mottram" __maintainer__ = "Bob Mottram"
__email__="bob@freedombone.net" __email__ = "bob@freedombone.net"
__status__="Production" __status__ = "Production"
import json
def getDonationTypes() -> str: def getDonationTypes() -> str:
return ('patreon','paypal','gofundme','liberapay', \ return ('patreon', 'paypal', 'gofundme', 'liberapay',
'kickstarter','indiegogo','crowdsupply', \ 'kickstarter', 'indiegogo', 'crowdsupply',
'subscribestar') 'subscribestar')
def getDonationUrl(actorJson: {}) -> str: def getDonationUrl(actorJson: {}) -> str:
"""Returns a link used for donations """Returns a link used for donations
""" """
if not actorJson.get('attachment'): if not actorJson.get('attachment'):
return '' return ''
donationType=getDonationTypes() donationType = getDonationTypes()
for propertyValue in actorJson['attachment']: for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'): if not propertyValue.get('name'):
continue continue
@ -28,58 +28,62 @@ def getDonationUrl(actorJson: {}) -> str:
continue continue
if not propertyValue.get('value'): if not propertyValue.get('value'):
continue continue
if propertyValue['type']!='PropertyValue': if propertyValue['type'] != 'PropertyValue':
continue continue
if '<a href="' not in propertyValue['value']: if '<a href="' not in propertyValue['value']:
continue continue
donateUrl=propertyValue['value'].split('<a href="')[1] donateUrl = propertyValue['value'].split('<a href="')[1]
if '"' in donateUrl: if '"' in donateUrl:
return donateUrl.split('"')[0] return donateUrl.split('"')[0]
return '' return ''
def setDonationUrl(actorJson: {},donateUrl: str) -> None:
def setDonationUrl(actorJson: {}, donateUrl: str) -> None:
"""Sets a link used for donations """Sets a link used for donations
""" """
if not actorJson.get('attachment'): if not actorJson.get('attachment'):
actorJson['attachment']=[] actorJson['attachment'] = []
donationType=getDonationTypes() donationType = getDonationTypes()
donateName=None donateName = None
for paymentService in donationType: for paymentService in donationType:
if paymentService in donateUrl: if paymentService in donateUrl:
donateName=paymentService donateName = paymentService
if not donateName: if not donateName:
return return
# remove any existing value # remove any existing value
propertyFound=None propertyFound = None
for propertyValue in actorJson['attachment']: for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'): if not propertyValue.get('name'):
continue continue
if not propertyValue.get('type'): if not propertyValue.get('type'):
continue continue
if not propertyValue['name'].lower()!=donateName: if not propertyValue['name'].lower() != donateName:
continue continue
propertyFound=propertyValue propertyFound = propertyValue
break break
if propertyFound: if propertyFound:
actorJson['attachment'].remove(propertyFound) actorJson['attachment'].remove(propertyFound)
donateValue='<a href="'+donateUrl+'" rel="me nofollow noopener noreferrer" target="_blank">'+donateUrl+'</a>' donateValue = \
'<a href="' + donateUrl + \
'" rel="me nofollow noopener noreferrer" target="_blank">' + \
donateUrl + '</a>'
for propertyValue in actorJson['attachment']: for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'): if not propertyValue.get('name'):
continue continue
if not propertyValue.get('type'): if not propertyValue.get('type'):
continue continue
if propertyValue['name'].lower()!=donateName: if propertyValue['name'].lower() != donateName:
continue continue
if propertyValue['type']!='PropertyValue': if propertyValue['type'] != 'PropertyValue':
continue continue
propertyValue['value']=donateValue propertyValue['value'] = donateValue
return return
newDonate={ newDonate = {
"name": donateName, "name": donateName,
"type": "PropertyValue", "type": "PropertyValue",
"value": donateValue "value": donateValue