forked from indymedia/epicyon
Move donation functions to their own module
parent
81f187acf2
commit
d17b984bbb
|
@ -23,8 +23,8 @@ from session import createSession
|
||||||
from webfinger import webfingerMeta
|
from webfinger import webfingerMeta
|
||||||
from webfinger import webfingerLookup
|
from webfinger import webfingerLookup
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from person import getDonationUrl
|
from donate import getDonationUrl
|
||||||
from person import setDonationUrl
|
from donate import setDonationUrl
|
||||||
from person import activateAccount
|
from person import activateAccount
|
||||||
from person import deactivateAccount
|
from person import deactivateAccount
|
||||||
from person import registerAccount
|
from person import registerAccount
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
__filename__ = "donate.py"
|
||||||
|
__author__ = "Bob Mottram"
|
||||||
|
__license__ = "AGPL3+"
|
||||||
|
__version__ = "1.0.0"
|
||||||
|
__maintainer__ = "Bob Mottram"
|
||||||
|
__email__ = "bob@freedombone.net"
|
||||||
|
__status__ = "Production"
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
def getDonationTypes() -> str:
|
||||||
|
return ('patreon','paypal','gofundme','liberapay', \
|
||||||
|
'kickstarter','indiegogo','crowdsupply', \
|
||||||
|
'subscribestar')
|
||||||
|
|
||||||
|
def getDonationUrl(actorJson: {}) -> str:
|
||||||
|
"""Returns a link used for donations
|
||||||
|
"""
|
||||||
|
if not actorJson.get('attachment'):
|
||||||
|
return ''
|
||||||
|
donationType=getDonationTypes()
|
||||||
|
for propertyValue in actorJson['attachment']:
|
||||||
|
if not propertyValue.get('name'):
|
||||||
|
continue
|
||||||
|
if propertyValue['name'].lower() not in donationType:
|
||||||
|
continue
|
||||||
|
if not propertyValue.get('type'):
|
||||||
|
continue
|
||||||
|
if not propertyValue.get('value'):
|
||||||
|
continue
|
||||||
|
if propertyValue['type']!='PropertyValue':
|
||||||
|
continue
|
||||||
|
if '<a href="' not in propertyValue['value']:
|
||||||
|
continue
|
||||||
|
donateUrl=propertyValue['value'].split('<a href="')[1]
|
||||||
|
if '"' in donateUrl:
|
||||||
|
return donateUrl.split('"')[0]
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def setDonationUrl(actorJson: {},donateUrl: str) -> None:
|
||||||
|
"""Sets a link used for donations
|
||||||
|
"""
|
||||||
|
if not actorJson.get('attachment'):
|
||||||
|
actorJson['attachment']=[]
|
||||||
|
|
||||||
|
donationType=getDonationTypes()
|
||||||
|
donateName=None
|
||||||
|
for paymentService in donationType:
|
||||||
|
if paymentService in donateUrl:
|
||||||
|
donateName=paymentService
|
||||||
|
if not donateName:
|
||||||
|
return
|
||||||
|
|
||||||
|
donateValue='<a href="'+donateUrl+'" rel="me nofollow noopener noreferrer" target="_blank">'+donateUrl+'</a>'
|
||||||
|
|
||||||
|
for propertyValue in actorJson['attachment']:
|
||||||
|
if not propertyValue.get('name'):
|
||||||
|
continue
|
||||||
|
if not propertyValue.get('type'):
|
||||||
|
continue
|
||||||
|
if propertyValue['name'].lower()!=donateName:
|
||||||
|
continue
|
||||||
|
if propertyValue['type']!='PropertyValue':
|
||||||
|
continue
|
||||||
|
propertyValue['value']=donateValue
|
||||||
|
return
|
||||||
|
|
||||||
|
newDonate={
|
||||||
|
"name": donateName,
|
||||||
|
"type": "PropertyValue",
|
||||||
|
"value": donateValue
|
||||||
|
}
|
||||||
|
actorJson['attachment'].append(newDonate)
|
65
person.py
65
person.py
|
@ -835,68 +835,3 @@ def personUnsnooze(baseDir: str,nickname: str,domain: str,snoozeActor: str) -> N
|
||||||
if writeSnoozedFile:
|
if writeSnoozedFile:
|
||||||
writeSnoozedFile.write(content)
|
writeSnoozedFile.write(content)
|
||||||
writeSnoozedFile.close()
|
writeSnoozedFile.close()
|
||||||
|
|
||||||
|
|
||||||
def getDonationTypes() -> str:
|
|
||||||
return ('patreon','paypal','gofundme','liberapay', \
|
|
||||||
'kickstarter','indiegogo','crowdsupply', \
|
|
||||||
'subscribestar')
|
|
||||||
|
|
||||||
def getDonationUrl(actorJson: {}) -> str:
|
|
||||||
"""Returns a link used for donations
|
|
||||||
"""
|
|
||||||
if not actorJson.get('attachment'):
|
|
||||||
return ''
|
|
||||||
donationType=getDonationTypes()
|
|
||||||
for propertyValue in actorJson['attachment']:
|
|
||||||
if not propertyValue.get('name'):
|
|
||||||
continue
|
|
||||||
if propertyValue['name'].lower() not in donationType:
|
|
||||||
continue
|
|
||||||
if not propertyValue.get('type'):
|
|
||||||
continue
|
|
||||||
if not propertyValue.get('value'):
|
|
||||||
continue
|
|
||||||
if propertyValue['type']!='PropertyValue':
|
|
||||||
continue
|
|
||||||
if '<a href="' not in propertyValue['value']:
|
|
||||||
continue
|
|
||||||
donateUrl=propertyValue['value'].split('<a href="')[1]
|
|
||||||
if '"' in donateUrl:
|
|
||||||
return donateUrl.split('"')[0]
|
|
||||||
return ''
|
|
||||||
|
|
||||||
def setDonationUrl(actorJson: {},donateUrl: str) -> None:
|
|
||||||
"""Sets a link used for donations
|
|
||||||
"""
|
|
||||||
if not actorJson.get('attachment'):
|
|
||||||
actorJson['attachment']=[]
|
|
||||||
|
|
||||||
donationType=getDonationTypes()
|
|
||||||
donateName=None
|
|
||||||
for paymentService in donationType:
|
|
||||||
if paymentService in donateUrl:
|
|
||||||
donateName=paymentService
|
|
||||||
if not donateName:
|
|
||||||
return
|
|
||||||
|
|
||||||
donateValue='<a href="'+donateUrl+'" rel="me nofollow noopener noreferrer" target="_blank">'+donateUrl+'</a>'
|
|
||||||
|
|
||||||
for propertyValue in actorJson['attachment']:
|
|
||||||
if not propertyValue.get('name'):
|
|
||||||
continue
|
|
||||||
if not propertyValue.get('type'):
|
|
||||||
continue
|
|
||||||
if propertyValue['name'].lower()!=donateName:
|
|
||||||
continue
|
|
||||||
if propertyValue['type']!='PropertyValue':
|
|
||||||
continue
|
|
||||||
propertyValue['value']=donateValue
|
|
||||||
return
|
|
||||||
|
|
||||||
newDonate={
|
|
||||||
"name": donateName,
|
|
||||||
"type": "PropertyValue",
|
|
||||||
"value": donateValue
|
|
||||||
}
|
|
||||||
actorJson['attachment'].append(newDonate)
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ from shutil import copyfileobj
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from person import personBoxJson
|
from person import personBoxJson
|
||||||
from person import isPersonSnoozed
|
from person import isPersonSnoozed
|
||||||
from person import getDonationUrl
|
from donate import getDonationUrl
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
|
|
Loading…
Reference in New Issue