Get actor from json

master
Bob Mottram 2019-08-28 09:58:16 +01:00
parent 94bd278ef6
commit 7b6f2a6468
2 changed files with 12 additions and 5 deletions

View File

@ -2515,6 +2515,7 @@ class PubServer(BaseHTTPRequestHandler):
searchStr=searchStr.replace('*','').strip() searchStr=searchStr.replace('*','').strip()
skillStr= \ skillStr= \
htmlSkillsSearch(self.server.baseDir,searchStr, \ htmlSkillsSearch(self.server.baseDir,searchStr, \
self.server.domainFull, \
maxPostsInFeed) maxPostsInFeed)
if skillStr: if skillStr:
msg=skillStr.encode('utf-8') msg=skillStr.encode('utf-8')

View File

@ -284,7 +284,7 @@ def htmlHashtagSearch(baseDir: str,hashtag: str,pageNumber: int,postsPerPage: in
hashtagSearchForm+=htmlFooter() hashtagSearchForm+=htmlFooter()
return hashtagSearchForm return hashtagSearchForm
def htmlSkillsSearch(baseDir: str,skillsearch: str,postsPerPage: int) -> str: def htmlSkillsSearch(baseDir: str,skillsearch: str,domainFull: str,postsPerPage: int) -> str:
"""Show a page containing search results for a skill """Show a page containing search results for a skill
""" """
if skillsearch.startswith('*'): if skillsearch.startswith('*'):
@ -302,11 +302,14 @@ def htmlSkillsSearch(baseDir: str,skillsearch: str,postsPerPage: int) -> str:
continue continue
if f.startswith('inbox@'): if f.startswith('inbox@'):
continue continue
actor=f.replace('.json','').replace('#','/')
actorFilename = os.path.join(subdir, f) actorFilename = os.path.join(subdir, f)
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
actorJson=commentjson.load(fp) actorJson=commentjson.load(fp)
if actorJson.get('skills') and actorJson.get('name') and actorJson.get('icon'): if actorJson.get('id') and \
actorJson.get('skills') and \
actorJson.get('name') and \
actorJson.get('icon'):
actor=actorJson['id']
for skillName,skillLevel in actorJson['skills'].items(): for skillName,skillLevel in actorJson['skills'].items():
skillName=skillName.lower() skillName=skillName.lower()
if skillName in skillsearch or skillsearch in skillName: if skillName in skillsearch or skillsearch in skillName:
@ -327,13 +330,16 @@ def htmlSkillsSearch(baseDir: str,skillsearch: str,postsPerPage: int) -> str:
continue continue
if f.startswith('inbox@'): if f.startswith('inbox@'):
continue continue
actor=f.replace('.json','').replace('#','/')
actorFilename = os.path.join(subdir, f) actorFilename = os.path.join(subdir, f)
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
cachedActorJson=commentjson.load(fp) cachedActorJson=commentjson.load(fp)
if cachedActorJson.get('actor'): if cachedActorJson.get('actor'):
actorJson=cachedActorJson['actor'] actorJson=cachedActorJson['actor']
if actorJson.get('skills') and actorJson.get('name') and actorJson.get('icon'): if actorJson.get('id') and \
actorJson.get('skills') and \
actorJson.get('name') and \
actorJson.get('icon'):
actor=actorJson['id']
for skillName,skillLevel in actorJson['skills'].items(): for skillName,skillLevel in actorJson['skills'].items():
skillName=skillName.lower() skillName=skillName.lower()
if skillName in skillsearch or skillsearch in skillName: if skillName in skillsearch or skillsearch in skillName: