mirror of https://gitlab.com/bashrc2/epicyon
flake8 format
parent
b7fc2b948d
commit
05d2d3d983
59
skills.py
59
skills.py
|
@ -6,9 +6,7 @@ __maintainer__="Bob Mottram"
|
|||
__email__ = "bob@freedombone.net"
|
||||
__status__ = "Production"
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from webfinger import webfingerHandle
|
||||
from auth import createBasicAuthHeader
|
||||
from posts import getPersonBox
|
||||
|
@ -18,7 +16,8 @@ from utils import getDomainFromActor
|
|||
from utils import loadJson
|
||||
from utils import saveJson
|
||||
|
||||
def setSkillLevel(baseDir: str,nickname: str,domain: str, \
|
||||
|
||||
def setSkillLevel(baseDir: str, nickname: str, domain: str,
|
||||
skill: str, skillLevelPercent: int) -> bool:
|
||||
"""Set a skill level for a person
|
||||
Setting skill level to zero removes it
|
||||
|
@ -40,6 +39,7 @@ def setSkillLevel(baseDir: str,nickname: str,domain: str, \
|
|||
saveJson(actorJson, actorFilename)
|
||||
return True
|
||||
|
||||
|
||||
def setSkills(baseDir: str, nickname: str, domain: str, skills: {}) -> None:
|
||||
actorFilename = baseDir + '/accounts/' + nickname + '@' + domain + '.json'
|
||||
if not os.path.isfile(actorFilename):
|
||||
|
@ -50,6 +50,7 @@ def setSkills(baseDir: str,nickname: str,domain: str,skills: {}) -> None:
|
|||
actorJson['skills'] = skills
|
||||
saveJson(actorJson, actorFilename)
|
||||
|
||||
|
||||
def getSkills(baseDir: str, nickname: str, domain: str) -> []:
|
||||
"""Returns the skills for a given person
|
||||
"""
|
||||
|
@ -64,7 +65,9 @@ def getSkills(baseDir: str,nickname: str,domain: str) -> []:
|
|||
return actorJson['skills']
|
||||
return None
|
||||
|
||||
def outboxSkills(baseDir: str,nickname: str,messageJson: {},debug: bool) -> bool:
|
||||
|
||||
def outboxSkills(baseDir: str, nickname: str, messageJson: {},
|
||||
debug: bool) -> bool:
|
||||
"""Handles receiving a skills update
|
||||
"""
|
||||
if not messageJson.get('type'):
|
||||
|
@ -83,19 +86,21 @@ def outboxSkills(baseDir: str,nickname: str,messageJson: {},debug: bool) -> bool
|
|||
return False
|
||||
domain, port = getDomainFromActor(messageJson['actor'])
|
||||
skill = messageJson['object'].replace('"', '').split(';')[0].strip()
|
||||
skillLevelPercentStr=messageJson['object'].replace('"','').split(';')[1].strip()
|
||||
skillLevelPercentStr = \
|
||||
messageJson['object'].replace('"', '').split(';')[1].strip()
|
||||
skillLevelPercent = 50
|
||||
if skillLevelPercentStr.isdigit():
|
||||
skillLevelPercent = int(skillLevelPercentStr)
|
||||
|
||||
return setSkillLevel(baseDir,nickname,domain, \
|
||||
return setSkillLevel(baseDir, nickname, domain,
|
||||
skill, skillLevelPercent)
|
||||
|
||||
|
||||
def sendSkillViaServer(baseDir: str, session, nickname: str, password: str,
|
||||
domain: str,port: int, \
|
||||
httpPrefix: str, \
|
||||
skill: str,skillLevelPercent: int, \
|
||||
cachedWebfingers: {},personCache: {}, \
|
||||
domain: str, port: int,
|
||||
httpPrefix: str,
|
||||
skill: str, skillLevelPercent: int,
|
||||
cachedWebfingers: {}, personCache: {},
|
||||
debug: bool, projectVersion: str) -> {}:
|
||||
"""Sets a skill for a person via c2s
|
||||
"""
|
||||
|
@ -109,16 +114,18 @@ def sendSkillViaServer(baseDir: str,session,nickname: str,password: str,
|
|||
if ':' not in domain:
|
||||
domainFull = domain + ':' + str(port)
|
||||
|
||||
toUrl=httpPrefix+'://'+domainFull+'/users/'+nickname
|
||||
ccUrl=httpPrefix+'://'+domainFull+'/users/'+nickname+'/followers'
|
||||
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||
toUrl = actor
|
||||
ccUrl = actor + '/followers'
|
||||
|
||||
if skillLevelPercent:
|
||||
skillStr = skill + ';' + str(skillLevelPercent)
|
||||
else:
|
||||
skillStr = skill + ';0'
|
||||
|
||||
newSkillJson = {
|
||||
'type': 'Skill',
|
||||
'actor': httpPrefix+'://'+domainFull+'/users/'+nickname,
|
||||
'actor': actor,
|
||||
'object': '"'+skillStr+'"',
|
||||
'to': [toUrl],
|
||||
'cc': [ccUrl]
|
||||
|
@ -127,7 +134,9 @@ def sendSkillViaServer(baseDir: str,session,nickname: str,password: str,
|
|||
handle = httpPrefix + '://' + domainFull + '/@' + nickname
|
||||
|
||||
# lookup the inbox for the To handle
|
||||
wfRequest=webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
|
||||
wfRequest = \
|
||||
webfingerHandle(session, handle, httpPrefix,
|
||||
cachedWebfingers,
|
||||
domain, projectVersion)
|
||||
if not wfRequest:
|
||||
if debug:
|
||||
|
@ -137,9 +146,13 @@ def sendSkillViaServer(baseDir: str,session,nickname: str,password: str,
|
|||
postToBox = 'outbox'
|
||||
|
||||
# get the actor inbox for the To handle
|
||||
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName= \
|
||||
getPersonBox(baseDir,session,wfRequest,personCache, \
|
||||
projectVersion,httpPrefix,nickname,domain,postToBox)
|
||||
(inboxUrl, pubKeyId, pubKey,
|
||||
fromPersonId, sharedInbox,
|
||||
capabilityAcquisition,
|
||||
avatarUrl, displayName) = getPersonBox(baseDir, session, wfRequest,
|
||||
personCache, projectVersion,
|
||||
httpPrefix, nickname, domain,
|
||||
postToBox)
|
||||
|
||||
if not inboxUrl:
|
||||
if debug:
|
||||
|
@ -150,18 +163,18 @@ def sendSkillViaServer(baseDir: str,session,nickname: str,password: str,
|
|||
print('DEBUG: No actor was found for ' + handle)
|
||||
return 4
|
||||
|
||||
authHeader=createBasicAuthHeader(Nickname,password)
|
||||
authHeader = createBasicAuthHeader(nickname, password)
|
||||
|
||||
headers = {
|
||||
'host': domain, \
|
||||
'Content-type': 'application/json', \
|
||||
'host': domain,
|
||||
'Content-type': 'application/json',
|
||||
'Authorization': authHeader
|
||||
}
|
||||
postResult = \
|
||||
postJson(session, newSkillJson, [], inboxUrl, headers, "inbox:write")
|
||||
#if not postResult:
|
||||
# if debug:
|
||||
# print('DEBUG: POST announce failed for c2s to '+inboxUrl)
|
||||
if not postResult:
|
||||
if debug:
|
||||
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
||||
# return 5
|
||||
|
||||
if debug:
|
||||
|
|
Loading…
Reference in New Issue