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
try: tries=0
with open(postFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
except Exception as e: with open(postFilename, 'r') as fp:
print(e) postJsonObject=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(postFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
except Exception as e: with open(postFilename, 'r') as fp:
print(e) postJsonObject=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(actorFilename, 'r') as fp: while tries<5:
actorJson=commentjson.load(fp) try:
except Exception as e: with open(actorFilename, 'r') as fp:
print(e) actorJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(actorFilename, 'r') as fp: while tries<5:
actorJson=commentjson.load(fp) try:
except Exception as e: with open(actorFilename, 'r') as fp:
print(e) actorJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(cacheFilename, 'r') as fp: while tries<5:
personJson=commentjson.load(fp) try:
except Exception as e: with open(cacheFilename, 'r') as fp:
print('ERROR: unable to load actor from cache '+cacheFilename) personJson=commentjson.load(fp)
print(e) break
except Exception as e:
print('ERROR: unable to load actor from cache '+cacheFilename)
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'):
with open('epicyon-profile.css', 'r') as cssfile: tries=0
css = cssfile.read() while tries<5:
try:
with open('epicyon-profile.css', 'r') as cssfile:
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
try: tries=0
with open(actorFilename, 'r') as fp: while tries<5:
actorJson=commentjson.load(fp) try:
loadedActor=True with open(actorFilename, 'r') as fp:
except Exception as e: actorJson=commentjson.load(fp)
print(e) loadedActor=True
break
except Exception as 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)
try: tries=0
with open(translationsFile, 'r') as fp: while tries<5:
httpd.translate=commentjson.load(fp) try:
except Exception as e: with open(translationsFile, 'r') as fp:
print('ERROR while loading translations '+translationsFile) httpd.translate=commentjson.load(fp)
print(e) break
except Exception as e:
print('ERROR while loading translations '+translationsFile)
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
try: tries=0
with open(actorFilename, 'r') as fp: while tries<5:
actor=commentjson.load(fp) try:
except Exception as e: with open(actorFilename, 'r') as fp:
print(e) actor=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(ocapFilename, 'r') as fp: while tries<5:
ocapJson=commentjson.load(fp) try:
except Exception as e: with open(ocapFilename, 'r') as fp:
print(e) ocapJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(ocapFilename, 'r') as fp: oc=None
oc=commentjson.load(fp) while tries<5:
except Exception as e: try:
print(e) with open(ocapFilename, 'r') as fp:
oc=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(ocapFilename, 'r') as fp: while tries<5:
ocapJson=commentjson.load(fp) try:
loadedOcap=True with open(ocapFilename, 'r') as fp:
except Exception as e: ocapJson=commentjson.load(fp)
print(e) loadedOcap=True
break
except Exception as 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
try: tries=0
with open(actorFilename, 'r') as fp: while tries<5:
existingPersonJson=commentjson.load(fp) try:
loadedActor=True with open(actorFilename, 'r') as fp:
except Exception as e: existingPersonJson=commentjson.load(fp)
print(e) loadedActor=True
break
except Exception as 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
try: tries=0
with open(postFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
loadedPost=True with open(postFilename, 'r') as fp:
except Exception as e: postJsonObject=commentjson.load(fp)
print(e) loadedPost=True
break
except Exception as 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
try: tries=0
with open(actorFile, 'r') as fp: while tries<5:
actorJson=commentjson.load(fp) try:
except Exception as e: with open(actorFile, 'r') as fp:
print(e) actorJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(actorFile, 'r') as fp: while tries<5:
actorJson=commentjson.load(fp) try:
except Exception as e: with open(actorFile, 'r') as fp:
print(e) actorJson=commentjson.load(fp)
break
except Exception as e:
print(e)
time.sleep(1)
tries+=1
if not actorJson: if not actorJson:
return 'Group' return 'Group'
return actorJson['name'] return actorJson['name']

31
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
try: tries=0
with open(postFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
except Exception as e: with open(postFilename, 'r') as fp:
print(e) postJsonObject=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(postFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
except Exception as e: with open(postFilename, 'r') as fp:
print(e) postJsonObject=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(followActivityfilename, 'r') as fp: while tries<5:
followJson=commentjson.load(fp) try:
except Exception as e: with open(followActivityfilename, 'r') as fp:
print(e) followJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(personFilename, 'r') as fp: while tries<5:
personJson=commentjson.load(fp) try:
except Exception as e: with open(personFilename, 'r') as fp:
print(e) personJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(actorFilename, 'r') as fp: while tries<5:
actorJson=commentjson.load(fp) try:
except Exception as e: with open(actorFilename, 'r') as fp:
print(e) actorJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(filename, 'r') as fp: while tries<5:
personJson=commentjson.load(fp) try:
except Exception as e: with open(filename, 'r') as fp:
print(e) personJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(filename, 'r') as fp: while tries<5:
personJson=commentjson.load(fp) try:
except Exception as e: with open(filename, 'r') as fp:
print(e) personJson=commentjson.load(fp)
break
except Exception as e:
print(e)
time.sleep(1)
tries+=1
if not personJson: if not personJson:
return False return False

135
posts.py
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
try: tries=0
with open(replyPostFilename, 'r') as fp: while tries<5:
replyToJson=commentjson.load(fp) try:
except Exception as e: with open(replyPostFilename, 'r') as fp:
print(e) replyToJson=commentjson.load(fp)
break
except Exception as 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):
try: tries=0
with open(ocapFilename, 'r') as fp: while tries<5:
oc=commentjson.load(fp) try:
if oc.get('id'): with open(ocapFilename, 'r') as fp:
capabilityIdList=[oc['id']] oc=commentjson.load(fp)
except Exception as e: if oc.get('id'):
print(e) capabilityIdList=[oc['id']]
break
except Exception as 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):
try: tries=0
with open(postFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
boxItems['orderedItems'].append(postJsonObject) with open(postFilename, 'r') as fp:
except Exception as e: postJsonObject=commentjson.load(fp)
print(e) boxItems['orderedItems'].append(postJsonObject)
break
except Exception as 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
try: tries=0
with open(sharedInboxFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
loadedPost=True with open(sharedInboxFilename, 'r') as fp:
except Exception as e: postJsonObject=commentjson.load(fp)
print(e) loadedPost=True
break
except Exception as 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
try: tries=0
with open(ocapFilename, 'r') as fp: while tries<5:
ocapJson=commentjson.load(fp) try:
loadedOcap=True with open(ocapFilename, 'r') as fp:
except Exception as e: ocapJson=commentjson.load(fp)
print(e) loadedOcap=True
break
except Exception as 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
try: tries=0
with open(searchFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
loadedPost=True with open(searchFilename, 'r') as fp:
except Exception as e: postJsonObject=commentjson.load(fp)
print(e) loadedPost=True
break
except Exception as 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
try: tries=0
with open(searchFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
loadedPost=True with open(searchFilename, 'r') as fp:
except Exception as e: postJsonObject=commentjson.load(fp)
print(e) loadedPost=True
break
except Exception as 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'])
try: tries=0
with open(announceFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
return postJsonObject with open(announceFilename, 'r') as fp:
except Exception as e: postJsonObject=commentjson.load(fp)
print(e) return postJsonObject
except Exception as 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
try: tries=0
with open(cachedActorFilename, 'r') as fp: while tries<5:
actorJson=commentjson.load(fp) try:
except Exception as e: with open(cachedActorFilename, 'r') as fp:
print(e) actorJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(postFilename, 'r') as fp: while tries<5:
postJsonObject=commentjson.load(fp) try:
except Exception as e: with open(postFilename, 'r') as fp:
print(e) postJsonObject=commentjson.load(fp)
break
except Exception as 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"}
try: tries=0
with open(filename, 'r') as fp: while tries<5:
wfJson=commentjson.load(fp) try:
except Exception as e: with open(filename, 'r') as fp:
print(e) wfJson=commentjson.load(fp)
break
except Exception as 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
try: tries=0
with open(postFilename, 'r') as fp: postJsonObject=None
postJsonObject=commentjson.load(fp) while tries<5:
except Exception as e: try:
print(e) with open(postFilename, 'r') as fp:
postJsonObject=commentjson.load(fp)
break
except Exception as 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):