From 0f0818994ea4b869f609388ac88b3feab66739b6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 13 May 2021 12:14:14 +0100 Subject: [PATCH] More standard occupation property --- daemon.py | 9 +++++---- person.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/daemon.py b/daemon.py index d72c34d61..7f820f302 100644 --- a/daemon.py +++ b/daemon.py @@ -4593,19 +4593,20 @@ class PubServer(BaseHTTPRequestHandler): # Other accounts (alsoKnownAs) occupationName = "" - if actorJson.get('occupationName'): - occupationName = actorJson['occupationName'] + if actorJson.get('hasOccupation'): + if actorJson['hasOccupation'].get('name'): + occupationName = actorJson['hasOccupation']['name'] if fields.get('occupationName'): fields['occupationName'] = \ removeHtml(fields['occupationName']) if occupationName != \ fields['occupationName']: - actorJson['occupationName'] = \ + actorJson['hasOccupation']['name'] = \ fields['occupationName'] actorChanged = True else: if occupationName: - actorJson['occupationName'] = '' + actorJson['hasOccupation']['name'] = '' actorChanged = True # Other accounts (alsoKnownAs) diff --git a/person.py b/person.py index 389a36026..4a7ac3c24 100644 --- a/person.py +++ b/person.py @@ -219,7 +219,8 @@ def getDefaultPersonContext() -> str: 'schema': 'http://schema.org#', 'suspended': 'toot:suspended', 'toot': 'http://joinmastodon.org/ns#', - 'value': 'schema:value' + 'value': 'schema:value', + 'Occupation': 'schema:Occupation' } @@ -296,7 +297,11 @@ def _createPersonBase(baseDir: str, nickname: str, domain: str, port: int, 'tts': personId + '/speaker', 'shares': personId + '/shares', 'orgSchema': None, - 'occupation': "", + 'hasOccupation': { + '@type': 'Occupation', + 'name': "", + 'skills': "", + }, 'skills': {}, 'roles': {}, 'availability': None, @@ -578,7 +583,26 @@ def personUpgradeActor(baseDir: str, personJson: {}, personJson['published'] = published updateActor = True + occupationName = '' + if personJson.get('occupation'): + occupationName = personJson['occupation'] + del personJson['occupation'] + + if not personJson.get('hasOccupation'): + personJson['hasOccupation'] = { + '@type': 'Occupation', + 'name': occupationName, + 'skills': "", + }, + updateActor = True + if updateActor: + personJson['@context'] = [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1', + getDefaultPersonContext() + ], + saveJson(personJson, filename) # also update the actor within the cache