Announce cache

master
Bob Mottram 2019-08-20 13:39:59 +01:00
parent 2650a522c2
commit 24090ea419
3 changed files with 30 additions and 13 deletions

View File

@ -2949,6 +2949,9 @@ def runDaemon(projectVersion, \
if not os.path.isdir(baseDir+'/cache/actors'): if not os.path.isdir(baseDir+'/cache/actors'):
print('Creating actors cache') print('Creating actors cache')
os.mkdir(baseDir+'/cache/actors') os.mkdir(baseDir+'/cache/actors')
if not os.path.isdir(baseDir+'/cache/announce'):
print('Creating announce cache')
os.mkdir(baseDir+'/cache/announce')
archiveDir=baseDir+'/archive' archiveDir=baseDir+'/archive'
if not os.path.isdir(archiveDir): if not os.path.isdir(archiveDir):

View File

@ -324,6 +324,9 @@ if not os.path.isdir(baseDir+'/cache'):
if not os.path.isdir(baseDir+'/cache/actors'): if not os.path.isdir(baseDir+'/cache/actors'):
print('Creating actors cache') print('Creating actors cache')
os.mkdir(baseDir+'/cache/actors') os.mkdir(baseDir+'/cache/actors')
if not os.path.isdir(baseDir+'/cache/announce'):
print('Creating announce cache')
os.mkdir(baseDir+'/cache/announce')
if args.domain: if args.domain:
domain=args.domain domain=args.domain

View File

@ -1023,20 +1023,31 @@ def individualPostAsHtml(baseDir: str, \
if postJsonObject.get('object'): if postJsonObject.get('object'):
if isinstance(postJsonObject['object'], str): if isinstance(postJsonObject['object'], str):
# get the announced post # get the announced post
print('Getting Announce content for '+postJsonObject['object']) announceCacheDir=baseDir+'/cache/announce/'+nickname
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} if not os.path.isdir(announceCacheDir):
announcedJson = getJson(session,postJsonObject['object'],asHeader,None,projectVersion,httpPrefix,domain) os.mkdir(announceCacheDir)
if announcedJson: announceFilename=announceCacheDir+'/'+postJsonObject['object'].replace('/','#')+'.json'
if not announcedJson.get('type'): if os.path.isfile(announceFilename):
return '' print('Reading cached Announce content for '+postJsonObject['object'])
if announcedJson['type']!='Create': with open(announceFilename, 'r') as fp:
return '' postJsonObject=commentjson.load(fp)
actorNickname=getNicknameFromActor(postJsonObject['actor'])
actorDomain,actorPort=getDomainFromActor(postJsonObject['actor'])
titleStr+='@'+actorNickname+'@'+actorDomain+' announced:<br>'
postJsonObject=announcedJson
else: else:
return '' print('Downloading Announce content for '+postJsonObject['object'])
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}
announcedJson = getJson(session,postJsonObject['object'],asHeader,None,projectVersion,httpPrefix,domain)
if announcedJson:
if not announcedJson.get('type'):
return ''
if announcedJson['type']!='Create':
return ''
actorNickname=getNicknameFromActor(postJsonObject['actor'])
actorDomain,actorPort=getDomainFromActor(postJsonObject['actor'])
titleStr+='@'+actorNickname+'@'+actorDomain+' announced:<br>'
postJsonObject=announcedJson
with open(announceFilename, 'w') as fp:
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
else:
return ''
else: else:
return '' return ''
if not isinstance(postJsonObject['object'], dict): if not isinstance(postJsonObject['object'], dict):