From 21a64bb21b289f53fca776b0b48ffbe572762e2a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 28 Jun 2019 21:00:25 +0100 Subject: [PATCH] Set person bio --- epicyon.py | 2 ++ person.py | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/epicyon.py b/epicyon.py index 016660fcd..8c6e4fc0d 100644 --- a/epicyon.py +++ b/epicyon.py @@ -8,6 +8,7 @@ __status__ = "Production" from person import createPerson from person import setPreferredUsername +from person import setBio from webfinger import webfingerHandle from posts import getUserPosts from session import createSession @@ -29,6 +30,7 @@ session = createSession(useTor) privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,True) setPreferredUsername(username,domain,'badger') +setBio(username,domain,'Some personal info') runDaemon(domain,port,useTor) #testHttpsig() diff --git a/person.py b/person.py index e5b9afb0d..f6eca5bb7 100644 --- a/person.py +++ b/person.py @@ -176,4 +176,24 @@ def setPreferredUsername(username: str, domain: str, preferredName: str) -> bool with open(filename, 'w') as fp: commentjson.dump(personJson, fp, indent=4, sort_keys=False) return True - + +def setBio(username: str, domain: str, bio: str) -> bool: + if len(bio)>32: + return False + handle=username.lower()+'@'+domain.lower() + baseDir=os.getcwd() + filename=baseDir+'/accounts/'+handle.lower()+'.json' + if not os.path.isfile(filename): + return False + personJson=None + with open(filename, 'r') as fp: + personJson=commentjson.load(fp) + if not personJson: + return False + if not personJson.get('publicKey'): + return False + personJson['publicKey']['summary']=bio + with open(filename, 'w') as fp: + commentjson.dump(personJson, fp, indent=4, sort_keys=False) + return True +