From 873b4953a777d6b2840b5c15b561d315b2ff303c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 14 Jul 2019 14:30:59 +0100 Subject: [PATCH] Option to set availability --- epicyon.py | 12 ++++++++++++ person.py | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/epicyon.py b/epicyon.py index dd077627..27e1b1be 100644 --- a/epicyon.py +++ b/epicyon.py @@ -16,6 +16,7 @@ from person import validNickname from person import setProfileImage from person import setSkillLevel from person import setRole +from person import setAvailability from webfinger import webfingerHandle from posts import getPosts from posts import createPublicPost @@ -181,6 +182,8 @@ parser.add_argument('--skill', dest='skill', type=str,default=None, \ help='Set a skill for a person') parser.add_argument('--level', dest='skillLevelPercent', type=int,default=None, \ help='Set a skill level for a person as a percentage, or zero to remove') +parser.add_argument('--status','--availability', dest='availability', type=str,default=None, \ + help='Set an availability status') args = parser.parse_args() debug=False @@ -536,6 +539,14 @@ if args.backgroundImage: print('Background image was not added for '+args.nickname) sys.exit() +if args.availability: + if not nickname: + print('No nickname given') + sys.exit() + if setAvailability(baseDir,nickname,domain,args.availability): + print('Availablity set to '+args.availability) + sys.exit() + if args.project: if not nickname: print('No nickname given') @@ -584,6 +595,7 @@ if args.testdata: setRole(baseDir,nickname,domain,'epicyon','tester') setRole(baseDir,nickname,domain,'epicyon','hacker') setRole(baseDir,nickname,domain,'someproject','assistant') + setAvailability(baseDir,nickname,domain,'busy') deleteAllPosts(baseDir,nickname,domain,'inbox') deleteAllPosts(baseDir,nickname,domain,'outbox') followPerson(baseDir,nickname,domain,'admin',domain,federationList,True) diff --git a/person.py b/person.py index adc8eec0..81b8277b 100644 --- a/person.py +++ b/person.py @@ -137,6 +137,21 @@ def setRole(baseDir: str,nickname: str,domain: str, \ commentjson.dump(actorJson, fp, indent=4, sort_keys=False) return True +def setAvailability(baseDir: str,nickname: str,domain: str, \ + status: str) -> bool: + """Set an availability status + """ + # avoid giant strings + if len(status)>128: + 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['availability']=status + 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 @@ -177,6 +192,7 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ 'following': httpPrefix+'://'+domain+'/users/'+nickname+'/following', 'skills': {}, 'roles': {}, + 'availability': None, 'icon': {'mediaType': 'image/png', 'type': 'Image', 'url': httpPrefix+'://'+domain+'/users/'+nickname+'/icon.png'},