Add some retries

main2
Bob Mottram 2019-10-11 19:03:58 +01:00
parent b0bd93e52d
commit 83d21e4de6
13 changed files with 373 additions and 187 deletions

View File

@ -6,6 +6,7 @@ __maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net" __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import time
import json import json
import commentjson import commentjson
from pprint import pprint from pprint import pprint
@ -68,12 +69,16 @@ def undoAnnounceCollectionEntry(postFilename: str,actor: str,debug: bool) -> Non
to shared items in shares.py. It's shares of posts, not shares of physical objects. to shared items in shares.py. It's shares of posts, not shares of physical objects.
""" """
postJsonObject=None postJsonObject=None
tries=0
while tries<5:
try: try:
with open(postFilename, 'r') as fp: with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2)
tries+=1
if postJsonObject: if postJsonObject:
if not postJsonObject.get('type'): if not postJsonObject.get('type'):
return return
@ -121,11 +126,16 @@ def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None:
It's shares of posts, not shares of physical objects. It's shares of posts, not shares of physical objects.
""" """
postJsonObject=None postJsonObject=None
tries=0
while tries<5:
try: try:
with open(postFilename, 'r') as fp: with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2)
tries+=1
if postJsonObject: if postJsonObject:
if not postJsonObject.get('object'): if not postJsonObject.get('object'):
if debug: if debug:

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import json import json
import time
import commentjson import commentjson
import os import os
from webfinger import webfingerHandle from webfinger import webfingerHandle
@ -27,11 +28,16 @@ def setAvailability(baseDir: str,nickname: str,domain: str, \
if not os.path.isfile(actorFilename): if not os.path.isfile(actorFilename):
return False return False
actorJson=None actorJson=None
tries=0
while tries<5:
try: try:
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
actorJson=commentjson.load(fp) actorJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2)
tries+=1
if actorJson: if actorJson:
actorJson['availability']=status actorJson['availability']=status
try: try:
@ -48,11 +54,16 @@ def getAvailability(baseDir: str,nickname: str,domain: str) -> str:
if not os.path.isfile(actorFilename): if not os.path.isfile(actorFilename):
return False return False
actorJson=None actorJson=None
tries=0
while tries<5:
try: try:
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
actorJson=commentjson.load(fp) actorJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2)
tries+=1
if actorJson: if actorJson:
if not actorJson.get('availability'): if not actorJson.get('availability'):
return None return None

View File

@ -41,12 +41,17 @@ def getPersonFromCache(baseDir: str,personUrl: str,personCache: {}) -> {}:
cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json' cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json'
if os.path.isfile(cacheFilename): if os.path.isfile(cacheFilename):
personJson=None personJson=None
tries=0
while tries<5:
try: try:
with open(cacheFilename, 'r') as fp: with open(cacheFilename, 'r') as fp:
personJson=commentjson.load(fp) personJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print('ERROR: unable to load actor from cache '+cacheFilename) print('ERROR: unable to load actor from cache '+cacheFilename)
print(e) print(e)
time.sleep(2)
tries+=1
if personJson: if personJson:
storePersonInCache(baseDir,personUrl,personJson,personCache) storePersonInCache(baseDir,personUrl,personJson,personCache)
loadedFromFile=True loadedFromFile=True

View File

@ -768,8 +768,16 @@ class PubServer(BaseHTTPRequestHandler):
# Note that this comes before the busy flag to avoid conflicts # Note that this comes before the busy flag to avoid conflicts
if self.path.endswith('.css'): if self.path.endswith('.css'):
if os.path.isfile('epicyon-profile.css'): if os.path.isfile('epicyon-profile.css'):
tries=0
while tries<5:
try:
with open('epicyon-profile.css', 'r') as cssfile: with open('epicyon-profile.css', 'r') as cssfile:
css = cssfile.read() css = cssfile.read()
break
except Exception as e:
print(e)
time.sleep(1)
tries+=1
msg=css.encode('utf-8') msg=css.encode('utf-8')
self._set_headers('text/css',len(msg),cookie) self._set_headers('text/css',len(msg),cookie)
self.wfile.write(msg) self.wfile.write(msg)
@ -2917,12 +2925,17 @@ class PubServer(BaseHTTPRequestHandler):
actorFilename=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'.json' actorFilename=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'.json'
if os.path.isfile(actorFilename): if os.path.isfile(actorFilename):
loadedActor=False loadedActor=False
tries=0
while tries<5:
try: try:
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
actorJson=commentjson.load(fp) actorJson=commentjson.load(fp)
loadedActor=True loadedActor=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedActor: if loadedActor:
actorChanged=False actorChanged=False
skillCtr=1 skillCtr=1
@ -4012,12 +4025,17 @@ def runDaemon(projectVersion, \
translationsFile=baseDir+'/translations/'+systemLanguage+'.json' translationsFile=baseDir+'/translations/'+systemLanguage+'.json'
print('System language: '+systemLanguage) print('System language: '+systemLanguage)
tries=0
while tries<5:
try: try:
with open(translationsFile, 'r') as fp: with open(translationsFile, 'r') as fp:
httpd.translate=commentjson.load(fp) httpd.translate=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print('ERROR while loading translations '+translationsFile) print('ERROR while loading translations '+translationsFile)
print(e) print(e)
time.sleep(1)
tries+=1
httpd.outboxThread={} httpd.outboxThread={}
httpd.newPostThread={} httpd.newPostThread={}

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import json import json
import time
import commentjson import commentjson
from pprint import pprint from pprint import pprint
import os import os
@ -336,11 +337,16 @@ def followApprovalRequired(baseDir: str,nicknameToFollow: str, \
actorFilename=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow+'.json' actorFilename=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow+'.json'
if os.path.isfile(actorFilename): if os.path.isfile(actorFilename):
actor=None actor=None
tries=0
while tries<5:
try: try:
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
actor=commentjson.load(fp) actor=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if actor: if actor:
if actor.get('manuallyApprovesFollowers'): if actor.get('manuallyApprovesFollowers'):
manuallyApproveFollows=actor['manuallyApprovesFollowers'] manuallyApproveFollows=actor['manuallyApprovesFollowers']
@ -864,11 +870,16 @@ def getFollowersOfActor(baseDir :str,actor :str,debug: bool) -> {}:
print('DEBUG: checking capabilities of'+account) print('DEBUG: checking capabilities of'+account)
if os.path.isfile(ocapFilename): if os.path.isfile(ocapFilename):
ocapJson=None ocapJson=None
tries=0
while tries<5:
try: try:
with open(ocapFilename, 'r') as fp: with open(ocapFilename, 'r') as fp:
ocapJson=commentjson.load(fp) ocapJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if ocapJson: if ocapJson:
if ocapJson.get('id'): if ocapJson.get('id'):
if debug: if debug:

View File

@ -312,11 +312,18 @@ def inboxCheckCapabilities(baseDir :str,nickname :str,domain :str, \
queue.pop(0) queue.pop(0)
return False return False
tries=0
oc=None
while tries<5:
try: try:
with open(ocapFilename, 'r') as fp: with open(ocapFilename, 'r') as fp:
oc=commentjson.load(fp) oc=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if not oc:
return False return False
if not oc.get('id'): if not oc.get('id'):
@ -374,12 +381,17 @@ def inboxPostRecipientsAdd(baseDir :str,httpPrefix :str,toList :[], \
if os.path.isfile(ocapFilename): if os.path.isfile(ocapFilename):
# read the granted capabilities and obtain the id # read the granted capabilities and obtain the id
loadedOcap=False loadedOcap=False
tries=0
while tries<5:
try: try:
with open(ocapFilename, 'r') as fp: with open(ocapFilename, 'r') as fp:
ocapJson=commentjson.load(fp) ocapJson=commentjson.load(fp)
loadedOcap=True loadedOcap=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedOcap: if loadedOcap:
if ocapJson.get('id'): if ocapJson.get('id'):
# append with the capabilities id # append with the capabilities id
@ -660,12 +672,17 @@ def personReceiveUpdate(baseDir: str, \
else: else:
if os.path.isfile(actorFilename): if os.path.isfile(actorFilename):
loadedActor=False loadedActor=False
tries=0
while tries<5:
try: try:
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
existingPersonJson=commentjson.load(fp) existingPersonJson=commentjson.load(fp)
loadedActor=True loadedActor=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedActor: if loadedActor:
if existingPersonJson['publicKey']['publicKeyPem']!=personJson['publicKey']['publicKeyPem']: if existingPersonJson['publicKey']['publicKeyPem']!=personJson['publicKey']['publicKeyPem']:
if debug: if debug:
@ -1066,12 +1083,17 @@ def receiveUndoAnnounce(session,handle: str,isGroup: bool,baseDir: str, \
print('DEBUG: announced/repeated post to be undone found in inbox') print('DEBUG: announced/repeated post to be undone found in inbox')
loadedPost=False loadedPost=False
tries=0
while tries<5:
try: try:
with open(postFilename, 'r') as fp: with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
loadedPost=True loadedPost=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedPost: if loadedPost:
if not postJsonObject.get('type'): if not postJsonObject.get('type'):
if postJsonObject['type']!='Announce': if postJsonObject['type']!='Announce':
@ -1251,11 +1273,16 @@ def groupHandle(baseDir: str,handle: str) -> bool:
if not os.path.isfile(actorFile): if not os.path.isfile(actorFile):
return False return False
actorJson=None actorJson=None
tries=0
while tries<5:
try: try:
with open(actorFile, 'r') as fp: with open(actorFile, 'r') as fp:
actorJson=commentjson.load(fp) actorJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if not actorJson: if not actorJson:
return False return False
return actorJson['type']=='Group' return actorJson['type']=='Group'
@ -1267,11 +1294,16 @@ def getGroupName(baseDir: str,handle: str) -> str:
if not os.path.isfile(actorFile): if not os.path.isfile(actorFile):
return False return False
actorJson=None actorJson=None
tries=0
while tries<5:
try: try:
with open(actorFile, 'r') as fp: with open(actorFile, 'r') as fp:
actorJson=commentjson.load(fp) actorJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if not actorJson: if not actorJson:
return 'Group' return 'Group'
return actorJson['name'] return actorJson['name']

11
like.py
View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import json import json
import time
import commentjson import commentjson
from pprint import pprint from pprint import pprint
from utils import urlPermitted from utils import urlPermitted
@ -23,11 +24,16 @@ def undoLikesCollectionEntry(postFilename: str,objectUrl: str,actor: str,debug:
"""Undoes a like for a particular actor """Undoes a like for a particular actor
""" """
postJsonObject=None postJsonObject=None
tries=0
while tries<5:
try: try:
with open(postFilename, 'r') as fp: with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if postJsonObject: if postJsonObject:
if not postJsonObject.get('type'): if not postJsonObject.get('type'):
@ -103,11 +109,16 @@ def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bo
"""Updates the likes collection within a post """Updates the likes collection within a post
""" """
postJsonObject=None postJsonObject=None
tries=0
while tries<5:
try: try:
with open(postFilename, 'r') as fp: with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if postJsonObject: if postJsonObject:
if not postJsonObject.get('object'): if not postJsonObject.get('object'):

View File

@ -98,11 +98,16 @@ def manualApproveFollowRequest(session,baseDir: str, \
followActivityfilename=requestsDir+'/'+handle+'.follow' followActivityfilename=requestsDir+'/'+handle+'.follow'
if os.path.isfile(followActivityfilename): if os.path.isfile(followActivityfilename):
followJson=None followJson=None
tries=0
while tries<5:
try: try:
with open(followActivityfilename, 'r') as fp: with open(followActivityfilename, 'r') as fp:
followJson=commentjson.load(fp) followJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if followJson: if followJson:
approveNickname=approveHandle.split('@')[0] approveNickname=approveHandle.split('@')[0]
approveDomain=approveHandle.split('@')[1].replace('\n','') approveDomain=approveHandle.split('@')[1].replace('\n','')

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import json import json
import time
import commentjson import commentjson
import os import os
import fileinput import fileinput
@ -91,11 +92,16 @@ def setProfileImage(baseDir: str,httpPrefix :str,nickname: str,domain: str, \
profileFilename=baseDir+'/accounts/'+handle+'/'+iconFilename profileFilename=baseDir+'/accounts/'+handle+'/'+iconFilename
personJson=None personJson=None
tries=0
while tries<5:
try: try:
with open(personFilename, 'r') as fp: with open(personFilename, 'r') as fp:
personJson=commentjson.load(fp) personJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if personJson: if personJson:
personJson[iconFilenameBase]['mediaType']=mediaType personJson[iconFilenameBase]['mediaType']=mediaType
@ -126,11 +132,16 @@ def setOrganizationScheme(baseDir: str,nickname: str,domain: str, \
return False return False
actorJson=None actorJson=None
tries=0
while tries<5:
try: try:
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
actorJson=commentjson.load(fp) actorJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if actorJson: if actorJson:
actorJson['orgSchema']=schema actorJson['orgSchema']=schema
@ -547,11 +558,16 @@ def setDisplayNickname(baseDir: str,nickname: str, domain: str, \
return False return False
personJson=None personJson=None
tries=0
while tries<5:
try: try:
with open(filename, 'r') as fp: with open(filename, 'r') as fp:
personJson=commentjson.load(fp) personJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if not personJson: if not personJson:
return False return False
@ -572,11 +588,16 @@ def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool:
return False return False
personJson=None personJson=None
tries=0
while tries<5:
try: try:
with open(filename, 'r') as fp: with open(filename, 'r') as fp:
personJson=commentjson.load(fp) personJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if not personJson: if not personJson:
return False return False

View File

@ -517,11 +517,16 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
replyPostFilename=locatePost(baseDir,nickname,domain,inReplyTo) replyPostFilename=locatePost(baseDir,nickname,domain,inReplyTo)
if replyPostFilename: if replyPostFilename:
replyToJson=None replyToJson=None
tries=0
while tries<5:
try: try:
with open(replyPostFilename, 'r') as fp: with open(replyPostFilename, 'r') as fp:
replyToJson=commentjson.load(fp) replyToJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if replyToJson: if replyToJson:
if replyToJson.get('object'): if replyToJson.get('object'):
if replyToJson['object'].get('sensitive'): if replyToJson['object'].get('sensitive'):
@ -566,13 +571,18 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
ocapFilename=getOcapFilename(baseDir,nickname,domain,toUrl,'granted') ocapFilename=getOcapFilename(baseDir,nickname,domain,toUrl,'granted')
if ocapFilename: if ocapFilename:
if os.path.isfile(ocapFilename): if os.path.isfile(ocapFilename):
tries=0
while tries<5:
try: try:
with open(ocapFilename, 'r') as fp: with open(ocapFilename, 'r') as fp:
oc=commentjson.load(fp) oc=commentjson.load(fp)
if oc.get('id'): if oc.get('id'):
capabilityIdList=[oc['id']] capabilityIdList=[oc['id']]
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
newPost = { newPost = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
'id': newPostId+'/activity', 'id': newPostId+'/activity',
@ -1719,12 +1729,17 @@ def createModeration(baseDir: str,nickname: str,domain: str,port: int,httpPrefix
for postUrl in pageLines: for postUrl in pageLines:
postFilename=boxDir+'/'+postUrl.replace('/','#')+'.json' postFilename=boxDir+'/'+postUrl.replace('/','#')+'.json'
if os.path.isfile(postFilename): if os.path.isfile(postFilename):
tries=0
while tries<5:
try: try:
with open(postFilename, 'r') as fp: with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
boxItems['orderedItems'].append(postJsonObject) boxItems['orderedItems'].append(postJsonObject)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if headerOnly: if headerOnly:
return boxHeader return boxHeader
@ -1876,12 +1891,17 @@ def createBoxBase(session,baseDir: str,boxname: str, \
sharedInboxFilename=os.path.join(sharedBoxDir, postFilename) sharedInboxFilename=os.path.join(sharedBoxDir, postFilename)
# get the actor from the shared post # get the actor from the shared post
loadedPost=False loadedPost=False
tries=0
while tries<5:
try: try:
with open(sharedInboxFilename, 'r') as fp: with open(sharedInboxFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
loadedPost=True loadedPost=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedPost: if loadedPost:
actorNickname=getNicknameFromActor(postJsonObject['actor']) actorNickname=getNicknameFromActor(postJsonObject['actor'])
actorDomain,actorPort=getDomainFromActor(postJsonObject['actor']) actorDomain,actorPort=getDomainFromActor(postJsonObject['actor'])
@ -1899,12 +1919,17 @@ def createBoxBase(session,baseDir: str,boxname: str, \
if os.path.isfile(ocapFilename): if os.path.isfile(ocapFilename):
# read the capabilities id # read the capabilities id
loadedOcap=False loadedOcap=False
tries=0
while tries<5:
try: try:
with open(ocapFilename, 'r') as fp: with open(ocapFilename, 'r') as fp:
ocapJson=commentjson.load(fp) ocapJson=commentjson.load(fp)
loadedOcap=True loadedOcap=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedOcap: if loadedOcap:
if ocapJson.get('id'): if ocapJson.get('id'):
if ocapJson['id'] in capsList: if ocapJson['id'] in capsList:
@ -2214,12 +2239,17 @@ def populateRepliesJson(baseDir: str,nickname: str,domain: str, \
if authorized or \ if authorized or \
'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read(): 'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read():
loadedPost=False loadedPost=False
tries=0
while tries<5:
try: try:
with open(searchFilename, 'r') as fp: with open(searchFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
loadedPost=True loadedPost=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedPost: if loadedPost:
if postJsonObject['object'].get('cc'): if postJsonObject['object'].get('cc'):
if authorized or \ if authorized or \
@ -2245,12 +2275,17 @@ def populateRepliesJson(baseDir: str,nickname: str,domain: str, \
'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read(): 'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read():
# get the json of the reply and append it to the collection # get the json of the reply and append it to the collection
loadedPost=False loadedPost=False
tries=0
while tries<5:
try: try:
with open(searchFilename, 'r') as fp: with open(searchFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
loadedPost=True loadedPost=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedPost: if loadedPost:
if postJsonObject['object'].get('cc'): if postJsonObject['object'].get('cc'):
if authorized or \ if authorized or \
@ -2290,12 +2325,16 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str,nickname: str,domain:
if os.path.isfile(announceFilename): if os.path.isfile(announceFilename):
print('Reading cached Announce content for '+postJsonObject['object']) print('Reading cached Announce content for '+postJsonObject['object'])
tries=0
while tries<5:
try: try:
with open(announceFilename, 'r') as fp: with open(announceFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
return postJsonObject return postJsonObject
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
else: else:
print('Downloading Announce content for '+postJsonObject['object']) print('Downloading Announce content for '+postJsonObject['object'])
asHeader={'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import os import os
import time
import shutil import shutil
import datetime import datetime
import commentjson import commentjson
@ -84,11 +85,16 @@ def getDisplayName(baseDir: str,actor: str,personCache: {}) -> str:
cachedActorFilename=baseDir+'/cache/actors/'+actor.replace('/','#')+'.json' cachedActorFilename=baseDir+'/cache/actors/'+actor.replace('/','#')+'.json'
if os.path.isfile(cachedActorFilename): if os.path.isfile(cachedActorFilename):
actorJson=None actorJson=None
tries=0
while tries<5:
try: try:
with open(cachedActorFilename, 'r') as fp: with open(cachedActorFilename, 'r') as fp:
actorJson=commentjson.load(fp) actorJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if actorJson: if actorJson:
if actorJson.get('name'): if actorJson.get('name'):
return(actorJson['name']) return(actorJson['name'])
@ -243,11 +249,16 @@ def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilena
"""Recursively deletes a post and its replies and attachments """Recursively deletes a post and its replies and attachments
""" """
postJsonObject=None postJsonObject=None
tries=0
while tries<5:
try: try:
with open(postFilename, 'r') as fp: with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if postJsonObject: if postJsonObject:
# remove any attachment # remove any attachment

View File

@ -13,6 +13,7 @@ import requests
import json import json
import commentjson import commentjson
import os import os
import time
from session import getJson from session import getJson
from cache import storeWebfingerInCache from cache import storeWebfingerInCache
from cache import getWebfingerFromCache from cache import getWebfingerFromCache
@ -222,9 +223,14 @@ def webfingerLookup(path: str,baseDir: str,port: int,debug: bool) -> {}:
print('DEBUG: WEBFINGER filename not found '+filename) print('DEBUG: WEBFINGER filename not found '+filename)
return None return None
wfJson={"nickname": "unknown"} wfJson={"nickname": "unknown"}
tries=0
while tries<5:
try: try:
with open(filename, 'r') as fp: with open(filename, 'r') as fp:
wfJson=commentjson.load(fp) wfJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return wfJson return wfJson

View File

@ -2766,11 +2766,17 @@ def getCalendarEvents(baseDir: str,nickname: str,domain: str,year: int,monthNumb
postFilename=locatePost(baseDir,nickname,domain,postId) postFilename=locatePost(baseDir,nickname,domain,postId)
if postFilename: if postFilename:
postJsonObject=None postJsonObject=None
tries=0
postJsonObject=None
while tries<5:
try: try:
with open(postFilename, 'r') as fp: with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp) postJsonObject=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2)
tries+=1
if postJsonObject: if postJsonObject:
if postJsonObject.get('object'): if postJsonObject.get('object'):
if isinstance(postJsonObject['object'], dict): if isinstance(postJsonObject['object'], dict):