2020-04-04 11:40:47 +00:00
|
|
|
__filename__ = "ssb.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
2021-01-26 10:07:42 +00:00
|
|
|
__version__ = "1.2.0"
|
2020-04-04 11:40:47 +00:00
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
2021-06-15 15:08:12 +00:00
|
|
|
__module_group__ = "Profile Metadata"
|
2020-02-26 14:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
def getSSBAddress(actorJson: {}) -> str:
|
|
|
|
"""Returns ssb address for the given actor
|
|
|
|
"""
|
|
|
|
if not actorJson.get('attachment'):
|
|
|
|
return ''
|
|
|
|
for propertyValue in actorJson['attachment']:
|
|
|
|
if not propertyValue.get('name'):
|
|
|
|
continue
|
|
|
|
if not propertyValue['name'].lower().startswith('ssb'):
|
|
|
|
continue
|
|
|
|
if not propertyValue.get('type'):
|
|
|
|
continue
|
|
|
|
if not propertyValue.get('value'):
|
|
|
|
continue
|
2020-04-04 11:40:47 +00:00
|
|
|
if propertyValue['type'] != 'PropertyValue':
|
2020-02-26 14:35:17 +00:00
|
|
|
continue
|
2020-04-04 11:40:47 +00:00
|
|
|
propertyValue['value'] = propertyValue['value'].strip()
|
2020-02-26 14:35:17 +00:00
|
|
|
if not propertyValue['value'].startswith('@'):
|
|
|
|
continue
|
2020-02-26 14:40:24 +00:00
|
|
|
if '=.' not in propertyValue['value']:
|
2020-02-26 14:35:17 +00:00
|
|
|
continue
|
|
|
|
if '"' in propertyValue['value']:
|
|
|
|
continue
|
2020-02-26 14:51:37 +00:00
|
|
|
if ' ' in propertyValue['value']:
|
|
|
|
continue
|
|
|
|
if ',' in propertyValue['value']:
|
|
|
|
continue
|
2020-02-26 14:35:17 +00:00
|
|
|
return propertyValue['value']
|
|
|
|
return ''
|
|
|
|
|
2020-04-04 11:40:47 +00:00
|
|
|
|
|
|
|
def setSSBAddress(actorJson: {}, ssbAddress: str) -> None:
|
2020-02-26 14:35:17 +00:00
|
|
|
"""Sets an ssb address for the given actor
|
|
|
|
"""
|
2020-07-06 10:23:11 +00:00
|
|
|
notSSBAddress = False
|
|
|
|
if not ssbAddress.startswith('@'):
|
|
|
|
notSSBAddress = True
|
|
|
|
if '=.' not in ssbAddress:
|
|
|
|
notSSBAddress = True
|
|
|
|
if '"' in ssbAddress:
|
|
|
|
notSSBAddress = True
|
|
|
|
if ' ' in ssbAddress:
|
|
|
|
notSSBAddress = True
|
|
|
|
if ',' in ssbAddress:
|
|
|
|
notSSBAddress = True
|
2020-12-12 15:31:28 +00:00
|
|
|
if '<' in ssbAddress:
|
|
|
|
notSSBAddress = True
|
2020-07-06 10:23:11 +00:00
|
|
|
|
2020-02-26 14:35:17 +00:00
|
|
|
if not actorJson.get('attachment'):
|
2020-04-04 11:40:47 +00:00
|
|
|
actorJson['attachment'] = []
|
2020-02-26 14:35:17 +00:00
|
|
|
|
|
|
|
# remove any existing value
|
2020-04-04 11:40:47 +00:00
|
|
|
propertyFound = None
|
2020-02-26 14:35:17 +00:00
|
|
|
for propertyValue in actorJson['attachment']:
|
|
|
|
if not propertyValue.get('name'):
|
|
|
|
continue
|
|
|
|
if not propertyValue.get('type'):
|
|
|
|
continue
|
|
|
|
if not propertyValue['name'].lower().startswith('ssb'):
|
|
|
|
continue
|
2020-04-04 11:40:47 +00:00
|
|
|
propertyFound = propertyValue
|
2020-02-26 14:35:17 +00:00
|
|
|
break
|
|
|
|
if propertyFound:
|
|
|
|
actorJson['attachment'].remove(propertyFound)
|
2020-07-06 10:23:11 +00:00
|
|
|
if notSSBAddress:
|
2020-02-26 14:35:17 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
for propertyValue in actorJson['attachment']:
|
|
|
|
if not propertyValue.get('name'):
|
|
|
|
continue
|
|
|
|
if not propertyValue.get('type'):
|
|
|
|
continue
|
|
|
|
if not propertyValue['name'].lower().startswith('ssb'):
|
|
|
|
continue
|
2020-04-04 11:40:47 +00:00
|
|
|
if propertyValue['type'] != 'PropertyValue':
|
2020-02-26 14:35:17 +00:00
|
|
|
continue
|
2020-04-04 11:40:47 +00:00
|
|
|
propertyValue['value'] = ssbAddress
|
2020-02-26 14:35:17 +00:00
|
|
|
return
|
|
|
|
|
2020-04-04 11:40:47 +00:00
|
|
|
newSSBAddress = {
|
2020-02-26 14:35:17 +00:00
|
|
|
"name": "SSB",
|
|
|
|
"type": "PropertyValue",
|
|
|
|
"value": ssbAddress
|
|
|
|
}
|
|
|
|
actorJson['attachment'].append(newSSBAddress)
|