diff --git a/person.py b/person.py index 53df7576d..53f94e194 100644 --- a/person.py +++ b/person.py @@ -85,6 +85,22 @@ def setProfileImage(baseDir: str,httpPrefix :str,nickname: str,domain: str, \ return True return False +def setSkillLevel(baseDir: str,nickname: str,domain: str, \ + skill: str,skillLevelPercent: int) -> bool: + """Set a skill level for a person + """ + if skillLevelPercent<0 or skillLevelPercent>100: + return False + actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json' + if not os.path.isfile(actorFilename): + return False + with open(actorFilename, 'r') as fp: + actorJson=commentjson.load(fp) + actorJson['skills'][skill]=skillLevelPercent + with open(actorFilename, 'w') as fp: + commentjson.dump(actorJson, fp, indent=4, sort_keys=False) + return True + def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ httpPrefix: str, saveToFile: bool,password=None) -> (str,str,{},{}): """Returns the private key, public key, actor and webfinger endpoint @@ -123,6 +139,8 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ 'featured': httpPrefix+'://'+domain+'/users/'+nickname+'/collections/featured', 'followers': httpPrefix+'://'+domain+'/users/'+nickname+'/followers', 'following': httpPrefix+'://'+domain+'/users/'+nickname+'/following', + 'skills': {}, + 'roles': {}, 'icon': {'mediaType': 'image/png', 'type': 'Image', 'url': httpPrefix+'://'+domain+'/users/'+nickname+'/icon.png'}, diff --git a/tests.py b/tests.py index 1cc2d64db..ff5cb01b0 100644 --- a/tests.py +++ b/tests.py @@ -40,6 +40,7 @@ from follow import sendFollowRequest from person import createPerson from person import setPreferredNickname from person import setBio +from person import setSkillLevel from auth import createBasicAuthHeader from auth import authorizeBasic from auth import storeBasicCredentials @@ -147,6 +148,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \ createPerson(path,nickname,domain,port,httpPrefix,True,password) deleteAllPosts(path,nickname,domain,'inbox') deleteAllPosts(path,nickname,domain,'outbox') + assert setSkillLevel(path,nickname,domain,'hacking',90) if hasFollows: followPerson(path,nickname,domain,'bob','127.0.0.100:61936', \ federationList,True)