From d17b984bbb266534f77f7ca6101a60753eaeb7ec Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 7 Nov 2019 12:14:17 +0000 Subject: [PATCH] Move donation functions to their own module --- daemon.py | 4 +-- donate.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ person.py | 65 ------------------------------------------- webinterface.py | 2 +- 4 files changed, 76 insertions(+), 68 deletions(-) create mode 100644 donate.py diff --git a/daemon.py b/daemon.py index 53a3f539..1eb4196e 100644 --- a/daemon.py +++ b/daemon.py @@ -23,8 +23,8 @@ from session import createSession from webfinger import webfingerMeta from webfinger import webfingerLookup from webfinger import webfingerHandle -from person import getDonationUrl -from person import setDonationUrl +from donate import getDonationUrl +from donate import setDonationUrl from person import activateAccount from person import deactivateAccount from person import registerAccount diff --git a/donate.py b/donate.py new file mode 100644 index 00000000..cf428277 --- /dev/null +++ b/donate.py @@ -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 ' 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=''+donateUrl+'' + + 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) diff --git a/person.py b/person.py index 1e500ca4..242dc500 100644 --- a/person.py +++ b/person.py @@ -835,68 +835,3 @@ def personUnsnooze(baseDir: str,nickname: str,domain: str,snoozeActor: str) -> N if writeSnoozedFile: writeSnoozedFile.write(content) 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 ' 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=''+donateUrl+'' - - 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) diff --git a/webinterface.py b/webinterface.py index f1386f5a..6b94c000 100644 --- a/webinterface.py +++ b/webinterface.py @@ -19,7 +19,7 @@ from shutil import copyfileobj from pprint import pprint from person import personBoxJson from person import isPersonSnoozed -from person import getDonationUrl +from donate import getDonationUrl from utils import getNicknameFromActor from utils import getDomainFromActor from utils import locatePost