More retries

main2
Bob Mottram 2019-10-12 10:37:21 +01:00
parent 1040f82312
commit 48c5424e33
18 changed files with 697 additions and 363 deletions

View File

@ -114,11 +114,16 @@ def undoAnnounceCollectionEntry(postFilename: str,actor: str,debug: bool) -> Non
del postJsonObject['object']['shares'] del postJsonObject['object']['shares']
else: else:
postJsonObject['object']['shares']['totalItems']=len(postJsonObject['object']['shares']['items']) postJsonObject['object']['shares']['totalItems']=len(postJsonObject['object']['shares']['items'])
tries=0
while tries<5:
try: try:
with open(postFilename, 'w') as fp: with open(postFilename, 'w') as fp:
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None: def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None:
"""Updates the announcements collection within a post """Updates the announcements collection within a post
@ -134,7 +139,7 @@ def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None:
break break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2) time.sleep(1)
tries+=1 tries+=1
if postJsonObject: if postJsonObject:
if not postJsonObject.get('object'): if not postJsonObject.get('object'):
@ -178,11 +183,16 @@ def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None:
if debug: if debug:
print('DEBUG: saving post with shares (announcements) added') print('DEBUG: saving post with shares (announcements) added')
pprint(postJsonObject) pprint(postJsonObject)
tries=0
while tries<5:
try: try:
with open(postFilename, 'w') as fp: with open(postFilename, 'w') as fp:
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def announcedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool: def announcedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool:
"""Returns True if the given post is announced by the given person """Returns True if the given post is announced by the given person
@ -245,11 +255,16 @@ def createAnnounce(session,baseDir: str,federationList: [], \
if saveToFile: if saveToFile:
outboxDir = createOutboxDir(nickname,domain,baseDir) outboxDir = createOutboxDir(nickname,domain,baseDir)
filename=outboxDir+'/'+newAnnounceId.replace('/','#')+'.json' filename=outboxDir+'/'+newAnnounceId.replace('/','#')+'.json'
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(newAnnounce, fp, indent=4, sort_keys=False) commentjson.dump(newAnnounce, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
announceNickname=None announceNickname=None
announceDomain=None announceDomain=None

View File

@ -36,15 +36,20 @@ def setAvailability(baseDir: str,nickname: str,domain: str, \
break break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2) time.sleep(1)
tries+=1 tries+=1
if actorJson: if actorJson:
actorJson['availability']=status actorJson['availability']=status
tries=0
while tries<5:
try: try:
with open(actorFilename, 'w') as fp: with open(actorFilename, 'w') as fp:
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return True return True
def getAvailability(baseDir: str,nickname: str,domain: str) -> str: def getAvailability(baseDir: str,nickname: str,domain: str) -> str:
@ -62,7 +67,7 @@ def getAvailability(baseDir: str,nickname: str,domain: str) -> str:
break break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2) time.sleep(1)
tries+=1 tries+=1
if actorJson: if actorJson:
if not actorJson.get('availability'): if not actorJson.get('availability'):

View File

@ -26,11 +26,16 @@ def storePersonInCache(baseDir: str,personUrl: str,personJson: {},personCache: {
if os.path.isdir(baseDir+'/cache/actors'): if os.path.isdir(baseDir+'/cache/actors'):
cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json' cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json'
if not os.path.isfile(cacheFilename): if not os.path.isfile(cacheFilename):
tries=0
while tries<5:
try: try:
with open(cacheFilename, 'w') as fp: with open(cacheFilename, 'w') as fp:
commentjson.dump(personJson, fp, indent=4, sort_keys=False) commentjson.dump(personJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def getPersonFromCache(baseDir: str,personUrl: str,personCache: {}) -> {}: def getPersonFromCache(baseDir: str,personUrl: str,personCache: {}) -> {}:
"""Get an actor from the cache """Get an actor from the cache
@ -50,7 +55,7 @@ def getPersonFromCache(baseDir: str,personUrl: str,personCache: {}) -> {}:
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) time.sleep(1)
tries+=1 tries+=1
if personJson: if personJson:
storePersonInCache(baseDir,personUrl,personJson,personCache) storePersonInCache(baseDir,personUrl,personJson,personCache)

View File

@ -127,11 +127,16 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
# if the capability already exists then load it from file # if the capability already exists then load it from file
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:
ocapAccept=commentjson.load(fp) ocapAccept=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
# otherwise create a new capability # otherwise create a new capability
if not ocapAccept: if not ocapAccept:
acceptedActorNickname=getNicknameFromActor(acceptedActor) acceptedActorNickname=getNicknameFromActor(acceptedActor)
@ -155,11 +160,16 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
ocapAccept['actor']=httpPrefix+"://"+fullDomain+'/users/'+nickname ocapAccept['actor']=httpPrefix+"://"+fullDomain+'/users/'+nickname
if saveToFile: if saveToFile:
tries=0
while tries<5:
try: try:
with open(ocapFilename, 'w') as fp: with open(ocapFilename, 'w') as fp:
commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False) commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return ocapAccept return ocapAccept
def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) -> bool: def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) -> bool:
@ -171,11 +181,16 @@ def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) ->
ocapFilename=getOcapFilename(baseDir,nickname,domain,ocap['actor'],'granted') ocapFilename=getOcapFilename(baseDir,nickname,domain,ocap['actor'],'granted')
if not ocapFilename: if not ocapFilename:
return False return False
tries=0
while tries<5:
try: try:
with open(ocapFilename, 'w') as fp: with open(ocapFilename, 'w') as fp:
commentjson.dump(ocap, fp, indent=4, sort_keys=False) commentjson.dump(ocap, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return True return True
def capabilitiesUpdate(baseDir: str,httpPrefix: str, \ def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
@ -217,11 +232,16 @@ def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
} }
# read the existing capability # read the existing capability
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
# set the new capabilities list. eg. ["inbox:write","objects:read"] # set the new capabilities list. eg. ["inbox:write","objects:read"]
ocapJson['capability']=updateCaps ocapJson['capability']=updateCaps
@ -240,11 +260,16 @@ def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
ocapUpdate['object']=ocapJson ocapUpdate['object']=ocapJson
# save it again # save it again
tries=0
while tries<5:
try: try:
with open(ocapFilename, 'w') as fp: with open(ocapFilename, 'w') as fp:
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False) commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return ocapUpdate return ocapUpdate
@ -267,20 +292,29 @@ def capabilitiesReceiveUpdate(baseDir :str, \
return False return False
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:
ocapJson['id']=newCapabilitiesId ocapJson['id']=newCapabilitiesId
ocapJson['capability']=capabilityList ocapJson['capability']=capabilityList
tries=0
while tries<5:
try: try:
with open(ocapFilename, 'w') as fp: with open(ocapFilename, 'w') as fp:
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False) commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
return True return True
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return False return False

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import os import os
import time
import json import json
import commentjson import commentjson
@ -18,39 +19,59 @@ def createConfig(baseDir: str) -> None:
return return
configJson = { configJson = {
} }
tries=0
while tries<5:
try: try:
with open(configFilename, 'w') as fp: with open(configFilename, 'w') as fp:
commentjson.dump(configJson, fp, indent=4, sort_keys=False) commentjson.dump(configJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def setConfigParam(baseDir: str, variableName: str, variableValue) -> None: def setConfigParam(baseDir: str, variableName: str, variableValue) -> None:
"""Sets a configuration value """Sets a configuration value
""" """
createConfig(baseDir) createConfig(baseDir)
configFilename=baseDir+'/config.json' configFilename=baseDir+'/config.json'
tries=0
while tries<5:
try: try:
with open(configFilename, 'r') as fp: with open(configFilename, 'r') as fp:
configJson=commentjson.load(fp) configJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
configJson[variableName]=variableValue configJson[variableName]=variableValue
tries=0
while tries<5:
try: try:
with open(configFilename, 'w') as fp: with open(configFilename, 'w') as fp:
commentjson.dump(configJson, fp, indent=4, sort_keys=False) commentjson.dump(configJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def getConfigParam(baseDir: str, variableName: str): def getConfigParam(baseDir: str, variableName: str):
"""Gets a configuration value """Gets a configuration value
""" """
createConfig(baseDir) createConfig(baseDir)
configFilename=baseDir+'/config.json' configFilename=baseDir+'/config.json'
tries=0
while tries<5:
try: try:
with open(configFilename, 'r') as fp: with open(configFilename, 'r') as fp:
configJson=commentjson.load(fp) configJson=commentjson.load(fp)
if configJson.get(variableName): if configJson.get(variableName):
return configJson[variableName] return configJson[variableName]
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return None return None

View File

@ -1468,12 +1468,17 @@ class PubServer(BaseHTTPRequestHandler):
if os.path.isfile(postFilename): if os.path.isfile(postFilename):
postJsonObject={} postJsonObject={}
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:
# Only authorized viewers get to see likes on posts # Only authorized viewers get to see likes on posts
# Otherwize marketers could gain more social graph info # Otherwize marketers could gain more social graph info
@ -1617,12 +1622,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:
if actorJson.get('roles'): if actorJson.get('roles'):
if self._requestHTTP(): if self._requestHTTP():
@ -1663,12 +1673,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:
if actorJson.get('skills'): if actorJson.get('skills'):
if self._requestHTTP(): if self._requestHTTP():
@ -1719,12 +1734,17 @@ class PubServer(BaseHTTPRequestHandler):
if os.path.isfile(postFilename): if os.path.isfile(postFilename):
postJsonObject={} postJsonObject={}
readPost=False readPost=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)
readPost=True readPost=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if not readPost: if not readPost:
self.send_response(429) self.send_response(429)
self.end_headers() self.end_headers()
@ -3057,19 +3077,29 @@ class PubServer(BaseHTTPRequestHandler):
os.remove(allowedInstancesFilename) os.remove(allowedInstancesFilename)
# save actor json file within accounts # save actor json file within accounts
if actorChanged: if actorChanged:
tries=0
while tries<5:
try: try:
with open(actorFilename, 'w') as fp: with open(actorFilename, 'w') as fp:
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
# also copy to the actors cache and personCache in memory # also copy to the actors cache and personCache in memory
storePersonInCache(self.server.baseDir,actorJson['id'],actorJson,self.server.personCache) storePersonInCache(self.server.baseDir,actorJson['id'],actorJson,self.server.personCache)
actorCacheFilename=self.server.baseDir+'/cache/actors/'+actorJson['id'].replace('/','#')+'.json' actorCacheFilename=self.server.baseDir+'/cache/actors/'+actorJson['id'].replace('/','#')+'.json'
tries=0
while tries<5:
try: try:
with open(actorCacheFilename, 'w') as fp: with open(actorCacheFilename, 'w') as fp:
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
# send actor update to followers # send actor update to followers
updateActorJson={ updateActorJson={
'type': 'Update', 'type': 'Update',

View File

@ -411,12 +411,16 @@ def storeFollowRequest(baseDir: str, \
if not os.path.isdir(requestsDir): if not os.path.isdir(requestsDir):
os.mkdir(requestsDir) os.mkdir(requestsDir)
followActivityfilename=requestsDir+'/'+approveHandle+'.follow' followActivityfilename=requestsDir+'/'+approveHandle+'.follow'
tries=0
while tries<5:
try: try:
with open(followActivityfilename, 'w') as fp: with open(followActivityfilename, 'w') as fp:
commentjson.dump(followJson, fp, indent=4, sort_keys=False) commentjson.dump(followJson, fp, indent=4, sort_keys=False)
return True return True
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return False return False
def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \

View File

@ -285,11 +285,16 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str, \
if debug: if debug:
print('Inbox queue item created') print('Inbox queue item created')
pprint(newQueueItem) pprint(newQueueItem)
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(newQueueItem, fp, indent=4, sort_keys=False) commentjson.dump(newQueueItem, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return filename return filename
def inboxCheckCapabilities(baseDir :str,nickname :str,domain :str, \ def inboxCheckCapabilities(baseDir :str,nickname :str,domain :str, \
@ -691,12 +696,17 @@ def personReceiveUpdate(baseDir: str, \
# save to cache in memory # save to cache in memory
storePersonInCache(baseDir,personJson['id'],personJson,personCache) storePersonInCache(baseDir,personJson['id'],personJson,personCache)
# save to cache on file # save to cache on file
tries=0
while tries<5:
try: try:
with open(actorFilename, 'w') as fp: with open(actorFilename, 'w') as fp:
commentjson.dump(personJson, fp, indent=4, sort_keys=False) commentjson.dump(personJson, fp, indent=4, sort_keys=False)
print('actor updated for '+personJson['id']) print('actor updated for '+personJson['id'])
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
# remove avatar if it exists so that it will be refreshed later # remove avatar if it exists so that it will be refreshed later
# when a timeline is constructed # when a timeline is constructed
@ -1546,11 +1556,16 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,postJsonObject,debug) obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,postJsonObject,debug)
# save the post to file # save the post to file
tries=0
while tries<5:
try: try:
with open(destinationFilename, 'w+') as fp: with open(destinationFilename, 'w+') as fp:
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
inboxUpdateCalendar(baseDir,handle,postJsonObject) inboxUpdateCalendar(baseDir,handle,postJsonObject)
@ -1903,12 +1918,17 @@ def runInboxQueue(projectVersion: str, \
if len(recipientsDictFollowers)>0: if len(recipientsDictFollowers)>0:
sharedInboxPostFilename=queueJson['destination'].replace(inboxHandle,inboxHandle) sharedInboxPostFilename=queueJson['destination'].replace(inboxHandle,inboxHandle)
if not os.path.isfile(sharedInboxPostFilename): if not os.path.isfile(sharedInboxPostFilename):
tries=0
while tries<5:
try: try:
with open(sharedInboxPostFilename, 'w') as fp: with open(sharedInboxPostFilename, 'w') as fp:
commentjson.dump(queueJson['post'],fp,indent=4, \ commentjson.dump(queueJson['post'],fp,indent=4, \
sort_keys=False) sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
# for posts addressed to specific accounts # for posts addressed to specific accounts
for handle,capsId in recipientsDict.items(): for handle,capsId in recipientsDict.items():

10
like.py
View File

@ -72,11 +72,16 @@ def undoLikesCollectionEntry(postFilename: str,objectUrl: str,actor: str,debug:
del postJsonObject['object']['likes'] del postJsonObject['object']['likes']
else: else:
postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items']) postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items'])
tries=0
while tries<5:
try: try:
with open(postFilename, 'w') as fp: with open(postFilename, 'w') as fp:
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def likedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool: def likedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool:
"""Returns True if the given post is liked by the given person """Returns True if the given post is liked by the given person
@ -159,11 +164,16 @@ def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bo
if debug: if debug:
print('DEBUG: saving post with likes added') print('DEBUG: saving post with likes added')
pprint(postJsonObject) pprint(postJsonObject)
tries=0
while tries<5:
try: try:
with open(postFilename, 'w') as fp: with open(postFilename, 'w') as fp:
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port: int, \ def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port: int, \
ccList: [],httpPrefix: str,objectUrl: str,clientToServer: bool, \ ccList: [],httpPrefix: str,objectUrl: str,clientToServer: bool, \

View File

@ -9,7 +9,7 @@ __status__ = "Production"
import os import os
import json import json
import commentjson import commentjson
import time
from follow import followedAccountAccepts from follow import followedAccountAccepts
from follow import followedAccountRejects from follow import followedAccountRejects
from follow import removeFromFollowRequests from follow import removeFromFollowRequests

View File

@ -106,11 +106,16 @@ def setProfileImage(baseDir: str,httpPrefix :str,nickname: str,domain: str, \
if personJson: if personJson:
personJson[iconFilenameBase]['mediaType']=mediaType personJson[iconFilenameBase]['mediaType']=mediaType
personJson[iconFilenameBase]['url']=httpPrefix+'://'+fullDomain+'/users/'+nickname+'/'+iconFilename personJson[iconFilenameBase]['url']=httpPrefix+'://'+fullDomain+'/users/'+nickname+'/'+iconFilename
tries=0
while tries<5:
try: try:
with open(personFilename, 'w') as fp: with open(personFilename, 'w') as fp:
commentjson.dump(personJson, fp, indent=4, sort_keys=False) commentjson.dump(personJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
cmd = '/usr/bin/convert '+imageFilename+' -size '+resolution+' -quality 50 '+profileFilename cmd = '/usr/bin/convert '+imageFilename+' -size '+resolution+' -quality 50 '+profileFilename
subprocess.call(cmd, shell=True) subprocess.call(cmd, shell=True)
@ -145,11 +150,16 @@ def setOrganizationScheme(baseDir: str,nickname: str,domain: str, \
if actorJson: if actorJson:
actorJson['orgSchema']=schema actorJson['orgSchema']=schema
tries=0
while tries<5:
try: try:
with open(actorFilename, 'w') as fp: with open(actorFilename, 'w') as fp:
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return True return True
def accountExists(baseDir: str,nickname: str,domain: str) -> bool: def accountExists(baseDir: str,nickname: str,domain: str) -> bool:
@ -269,11 +279,16 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
if not os.path.isdir(baseDir+peopleSubdir+'/'+handle+'/queue'): if not os.path.isdir(baseDir+peopleSubdir+'/'+handle+'/queue'):
os.mkdir(baseDir+peopleSubdir+'/'+handle+'/queue') os.mkdir(baseDir+peopleSubdir+'/'+handle+'/queue')
filename=baseDir+peopleSubdir+'/'+handle+'.json' filename=baseDir+peopleSubdir+'/'+handle+'.json'
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(newPerson, fp, indent=4, sort_keys=False) commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
# save to cache # save to cache
if not os.path.isdir(baseDir+'/cache'): if not os.path.isdir(baseDir+'/cache'):
@ -281,11 +296,16 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
if not os.path.isdir(baseDir+'/cache/actors'): if not os.path.isdir(baseDir+'/cache/actors'):
os.mkdir(baseDir+'/cache/actors') os.mkdir(baseDir+'/cache/actors')
cacheFilename=baseDir+'/cache/actors/'+newPerson['id'].replace('/','#')+'.json' cacheFilename=baseDir+'/cache/actors/'+newPerson['id'].replace('/','#')+'.json'
tries=0
while tries<5:
try: try:
with open(cacheFilename, 'w') as fp: with open(cacheFilename, 'w') as fp:
commentjson.dump(newPerson, fp, indent=4, sort_keys=False) commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
# save the private key # save the private key
privateKeysSubdir='/keys/private' privateKeysSubdir='/keys/private'
@ -442,7 +462,7 @@ def personLookup(domain: str,path: str,baseDir: str) -> {}:
break break
except: except:
print('WARN: Failed to load actor '+filename) print('WARN: Failed to load actor '+filename)
time.sleep(2) time.sleep(1)
tries+=1 tries+=1
if tries>=5: if tries>=5:
return None return None
@ -572,11 +592,16 @@ def setDisplayNickname(baseDir: str,nickname: str, domain: str, \
if not personJson: if not personJson:
return False return False
personJson['name']=displayName personJson['name']=displayName
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(personJson, fp, indent=4, sort_keys=False) commentjson.dump(personJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return True return True
def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool: def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool:
@ -605,11 +630,16 @@ def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool:
return False return False
personJson['summary']=bio personJson['summary']=bio
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(personJson, fp, indent=4, sort_keys=False) commentjson.dump(personJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return True return True

View File

@ -415,11 +415,16 @@ def savePostToBox(baseDir: str,httpPrefix: str,postId: str, \
boxDir = createPersonDir(nickname,domain,baseDir,boxname) boxDir = createPersonDir(nickname,domain,baseDir,boxname)
filename=boxDir+'/'+postId.replace('/','#')+'.json' filename=boxDir+'/'+postId.replace('/','#')+'.json'
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return filename return filename
def updateHashtagsIndex(baseDir: str,tag: {},newPostId: str) -> None: def updateHashtagsIndex(baseDir: str,tag: {},newPostId: str) -> None:
@ -2388,10 +2393,14 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str,nickname: str,domain:
rejectAnnounce(announceFilename) rejectAnnounce(announceFilename)
return None return None
postJsonObject=announcedJson postJsonObject=announcedJson
tries=0
while tries<5:
try: try:
with open(announceFilename, 'w') as fp: with open(announceFilename, 'w') as fp:
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
return postJsonObject return postJsonObject
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return None return None

View File

@ -9,6 +9,7 @@ __status__ = "Production"
import json import json
import commentjson import commentjson
import os import os
import time
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
from posts import getPersonBox from posts import getPersonBox
@ -29,21 +30,31 @@ def clearModeratorStatus(baseDir: str) -> None:
filename=os.path.join(baseDir+'/accounts/', filename) filename=os.path.join(baseDir+'/accounts/', filename)
if '"moderator"' in open(filename).read(): if '"moderator"' in open(filename).read():
actorJson=None actorJson=None
tries=0
while tries<5:
try: try:
with open(filename, 'r') as fp: with open(filename, '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['roles'].get('instance'): if actorJson['roles'].get('instance'):
if 'moderator' in actorJson['roles']['instance']: if 'moderator' in actorJson['roles']['instance']:
actorJson['roles']['instance'].remove('moderator') actorJson['roles']['instance'].remove('moderator')
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def addModerator(baseDir: str,nickname: str,domain: str) -> None: def addModerator(baseDir: str,nickname: str,domain: str) -> None:
"""Adds a moderator nickname to the file """Adds a moderator nickname to the file
@ -98,11 +109,16 @@ def setRole(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:
if role: if role:
@ -123,11 +139,16 @@ def setRole(baseDir: str,nickname: str,domain: str, \
# if the project contains no roles then remove it # if the project contains no roles then remove it
if len(actorJson['roles'][project])==0: if len(actorJson['roles'][project])==0:
del actorJson['roles'][project] del actorJson['roles'][project]
tries=0
while tries<5:
try: try:
with open(actorFilename, 'w') as fp: with open(actorFilename, 'w') as fp:
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return True return True
def getRoles(baseDir: str,nickname: str,domain: str, \ def getRoles(baseDir: str,nickname: str,domain: str, \
@ -139,11 +160,16 @@ def getRoles(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:
if not actorJson.get('roles'): if not actorJson.get('roles'):

View File

@ -26,11 +26,16 @@ def removeShare(baseDir: str,nickname: str,domain: str, \
""" """
sharesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json' sharesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json'
if os.path.isfile(sharesFilename): if os.path.isfile(sharesFilename):
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'r') as fp: with open(sharesFilename, 'r') as fp:
sharesJson=commentjson.load(fp) sharesJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
itemID=displayName.replace(' ','') itemID=displayName.replace(' ','')
if sharesJson.get(itemID): if sharesJson.get(itemID):
@ -45,11 +50,16 @@ def removeShare(baseDir: str,nickname: str,domain: str, \
os.remove(itemIDfile+'.gif') os.remove(itemIDfile+'.gif')
# remove the item itself # remove the item itself
del sharesJson[itemID] del sharesJson[itemID]
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'w') as fp: with open(sharesFilename, 'w') as fp:
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False) commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def addShare(baseDir: str, \ def addShare(baseDir: str, \
httpPrefix: str,nickname: str,domain: str,port: int, \ httpPrefix: str,nickname: str,domain: str,port: int, \
@ -66,11 +76,16 @@ def addShare(baseDir: str, \
sharesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json' sharesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json'
sharesJson={} sharesJson={}
if os.path.isfile(sharesFilename): if os.path.isfile(sharesFilename):
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'r') as fp: with open(sharesFilename, 'r') as fp:
sharesJson=commentjson.load(fp) sharesJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
duration=duration.lower() duration=duration.lower()
durationSec=0 durationSec=0
@ -146,11 +161,16 @@ def addShare(baseDir: str, \
"expire": durationSec "expire": durationSec
} }
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'w') as fp: with open(sharesFilename, 'w') as fp:
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False) commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def expireShares(baseDir: str,nickname: str,domain: str) -> None: def expireShares(baseDir: str,nickname: str,domain: str) -> None:
"""Removes expired items from shares """Removes expired items from shares
@ -162,11 +182,16 @@ def expireShares(baseDir: str,nickname: str,domain: str) -> None:
sharesFilename=baseDir+'/accounts/'+handle+'/shares.json' sharesFilename=baseDir+'/accounts/'+handle+'/shares.json'
if os.path.isfile(sharesFilename): if os.path.isfile(sharesFilename):
sharesJson=None sharesJson=None
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'r') as fp: with open(sharesFilename, 'r') as fp:
sharesJson=commentjson.load(fp) sharesJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if sharesJson: if sharesJson:
currTime=int(time.time()) currTime=int(time.time())
deleteItemID=[] deleteItemID=[]
@ -184,11 +209,16 @@ def expireShares(baseDir: str,nickname: str,domain: str) -> None:
os.remove(itemIDfile+'.jpg') os.remove(itemIDfile+'.jpg')
if os.path.isfile(itemIDfile+'.gif'): if os.path.isfile(itemIDfile+'.gif'):
os.remove(itemIDfile+'.gif') os.remove(itemIDfile+'.gif')
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'w') as fp: with open(sharesFilename, 'w') as fp:
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False) commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def getSharesFeedForPerson(baseDir: str, \ def getSharesFeedForPerson(baseDir: str, \
domain: str,port: int, \ domain: str,port: int, \
@ -239,12 +269,17 @@ def getSharesFeedForPerson(baseDir: str, \
if headerOnly: if headerOnly:
noOfShares=0 noOfShares=0
if os.path.isfile(sharesFilename): if os.path.isfile(sharesFilename):
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'r') as fp: with open(sharesFilename, 'r') as fp:
sharesJson=commentjson.load(fp) sharesJson=commentjson.load(fp)
noOfShares=len(sharesJson.items()) noOfShares=len(sharesJson.items())
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
shares = { shares = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/shares?page=1', 'first': httpPrefix+'://'+domain+'/users/'+nickname+'/shares?page=1',
@ -273,11 +308,16 @@ def getSharesFeedForPerson(baseDir: str, \
totalCtr=0 totalCtr=0
sharesJson=None sharesJson=None
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'r') as fp: with open(sharesFilename, 'r') as fp:
sharesJson=commentjson.load(fp) sharesJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if sharesJson: if sharesJson:
for itemID,item in sharesJson.items(): for itemID,item in sharesJson.items():

View File

@ -9,6 +9,7 @@ __status__ = "Production"
import json import json
import commentjson import commentjson
import os import os
import time
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
from posts import getPersonBox from posts import getPersonBox
@ -28,11 +29,16 @@ def setSkillLevel(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:
if not actorJson.get('skills'): if not actorJson.get('skills'):
@ -41,11 +47,16 @@ def setSkillLevel(baseDir: str,nickname: str,domain: str, \
actorJson['skills'][skill]=skillLevelPercent actorJson['skills'][skill]=skillLevelPercent
else: else:
del actorJson['skills'][skill] del actorJson['skills'][skill]
tries=0
while tries<5:
try: try:
with open(actorFilename, 'w') as fp: with open(actorFilename, 'w') as fp:
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return True return True
def setSkills(baseDir: str,nickname: str,domain: str,skills: {}) -> None: def setSkills(baseDir: str,nickname: str,domain: str,skills: {}) -> None:
@ -54,19 +65,29 @@ def setSkills(baseDir: str,nickname: str,domain: str,skills: {}) -> None:
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['skills']=skills actorJson['skills']=skills
tries=0
while tries<5:
try: try:
with open(actorFilename, 'w') as fp: with open(actorFilename, 'w') as fp:
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
def getSkills(baseDir: str,nickname: str,domain: str) -> []: def getSkills(baseDir: str,nickname: str,domain: str) -> []:
"""Returns the skills for a given person """Returns the skills for a given person
@ -76,11 +97,16 @@ def getSkills(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:
if not actorJson.get('skills'): if not actorJson.get('skills'):

View File

@ -92,19 +92,29 @@ def storeWebfingerEndpoint(nickname: str,domain: str,port: int,baseDir: str, \
if not os.path.isdir(baseDir+wfSubdir): if not os.path.isdir(baseDir+wfSubdir):
os.mkdir(baseDir+wfSubdir) os.mkdir(baseDir+wfSubdir)
filename=baseDir+wfSubdir+'/'+handle.lower()+'.json' filename=baseDir+wfSubdir+'/'+handle.lower()+'.json'
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(wfJson, fp, indent=4, sort_keys=False) commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if nickname=='inbox': if nickname=='inbox':
handle=originalDomain+'@'+domain handle=originalDomain+'@'+domain
filename=baseDir+wfSubdir+'/'+handle.lower()+'.json' filename=baseDir+wfSubdir+'/'+handle.lower()+'.json'
tries=0
while tries<5:
try: try:
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
commentjson.dump(wfJson, fp, indent=4, sort_keys=False) commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
return True return True
def createWebfingerEndpoint(nickname: str,domain: str,port: int, \ def createWebfingerEndpoint(nickname: str,domain: str,port: int, \

View File

@ -150,12 +150,17 @@ def htmlSearchEmoji(translate: {},baseDir: str,searchStr: str) -> str:
return emojiForm return emojiForm
loadedEmoji=False loadedEmoji=False
tries=0
while tries<5:
try: try:
with open(emojiLookupFilename, 'r') as fp: with open(emojiLookupFilename, 'r') as fp:
emojiJson=commentjson.load(fp) emojiJson=commentjson.load(fp)
loadedEmoji=True loadedEmoji=True
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if loadedEmoji: if loadedEmoji:
results={} results={}
for emojiName,filename in emojiJson.items(): for emojiName,filename in emojiJson.items():
@ -219,11 +224,16 @@ def htmlSearchSharedItems(translate: {}, \
continue continue
sharesJson=None sharesJson=None
tries=0
while tries<5:
try: try:
with open(sharesFilename, 'r') as fp: with open(sharesFilename, 'r') as fp:
sharesJson=commentjson.load(fp) sharesJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if not sharesJson: if not sharesJson:
continue continue
@ -380,12 +390,17 @@ def htmlHashtagSearch(translate: {}, \
index-=1 index-=1
continue continue
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 isPublicPost(postJsonObject): if not isPublicPost(postJsonObject):
index-=1 index-=1
@ -427,12 +442,17 @@ def htmlSkillsSearch(translate: {},baseDir: str, \
continue continue
actorFilename = os.path.join(subdir, f) actorFilename = os.path.join(subdir, f)
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:
if actorJson.get('id') and \ if actorJson.get('id') and \
actorJson.get('skills') and \ actorJson.get('skills') and \
@ -462,12 +482,17 @@ def htmlSkillsSearch(translate: {},baseDir: str, \
continue continue
actorFilename = os.path.join(subdir, f) actorFilename = os.path.join(subdir, f)
loadedActor=False loadedActor=False
tries=0
while tries<5:
try: try:
with open(actorFilename, 'r') as fp: with open(actorFilename, 'r') as fp:
cachedActorJson=commentjson.load(fp) cachedActorJson=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 cachedActorJson.get('actor'): if cachedActorJson.get('actor'):
actorJson=cachedActorJson['actor'] actorJson=cachedActorJson['actor']
@ -543,12 +568,17 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int)
bioStr='' bioStr=''
manuallyApprovesFollowers='' manuallyApprovesFollowers=''
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:
if actorJson.get('name'): if actorJson.get('name'):
displayNickname=actorJson['name'] displayNickname=actorJson['name']
@ -1588,12 +1618,17 @@ def followerApprovalActive(baseDir: str,nickname: str,domain: str) -> bool:
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json' actorFilename=baseDir+'/accounts/'+nickname+'@'+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:
if actorJson.get('manuallyApprovesFollowers'): if actorJson.get('manuallyApprovesFollowers'):
manuallyApprovesFollowers=actorJson['manuallyApprovesFollowers'] manuallyApprovesFollowers=actorJson['manuallyApprovesFollowers']
@ -2323,12 +2358,17 @@ def htmlIndividualPost(translate: {}, \
if not postFilename: if not postFilename:
break break
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:
postStr= \ postStr= \
individualPostAsHtml(iconsDir,translate,None, \ individualPostAsHtml(iconsDir,translate,None, \
@ -2395,12 +2435,16 @@ def htmlRemoveSharedItem(translate: {},baseDir: str,actor: str,shareName: str) -
if not os.path.isfile(sharesFile): if not os.path.isfile(sharesFile):
return None return None
sharesJson=None sharesJson=None
tries=0
while tries<5:
try: try:
with open(sharesFile, 'r') as fp: with open(sharesFile, 'r') as fp:
sharesJson=commentjson.load(fp) sharesJson=commentjson.load(fp)
break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1)
tries+=1
if not sharesJson: if not sharesJson:
return None return None
@ -2458,11 +2502,16 @@ def htmlDeletePost(translate,pageNumber: int, \
return None return None
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 not postJsonObject: if not postJsonObject:
return None return None
@ -2776,7 +2825,7 @@ def getCalendarEvents(baseDir: str,nickname: str,domain: str,year: int,monthNumb
break break
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(2) time.sleep(1)
tries+=1 tries+=1
if postJsonObject: if postJsonObject:
if postJsonObject.get('object'): if postJsonObject.get('object'):