mirror of https://gitlab.com/bashrc2/epicyon
More retries
parent
1040f82312
commit
48c5424e33
47
announce.py
47
announce.py
|
@ -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'])
|
||||||
try:
|
tries=0
|
||||||
with open(postFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(postFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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)
|
||||||
try:
|
tries=0
|
||||||
with open(postFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(postFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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'
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(newAnnounce, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(newAnnounce, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(1)
|
||||||
|
tries+=1
|
||||||
|
|
||||||
announceNickname=None
|
announceNickname=None
|
||||||
announceDomain=None
|
announceDomain=None
|
||||||
|
|
|
@ -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
|
||||||
try:
|
tries=0
|
||||||
with open(actorFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(actorFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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'):
|
||||||
|
|
17
cache.py
17
cache.py
|
@ -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):
|
||||||
try:
|
tries=0
|
||||||
with open(cacheFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(cacheFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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)
|
||||||
|
|
106
capabilities.py
106
capabilities.py
|
@ -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):
|
||||||
try:
|
tries=0
|
||||||
with open(ocapFilename, 'r') as fp:
|
while tries<5:
|
||||||
ocapAccept=commentjson.load(fp)
|
try:
|
||||||
except Exception as e:
|
with open(ocapFilename, 'r') as fp:
|
||||||
print(e)
|
ocapAccept=commentjson.load(fp)
|
||||||
|
break
|
||||||
|
except Exception as 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:
|
||||||
try:
|
tries=0
|
||||||
with open(ocapFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(ocapFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(ocapFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(ocapFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
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
|
||||||
|
|
||||||
# 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
|
||||||
try:
|
tries=0
|
||||||
with open(ocapFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(ocapFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
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:
|
||||||
ocapJson['id']=newCapabilitiesId
|
ocapJson['id']=newCapabilitiesId
|
||||||
ocapJson['capability']=capabilityList
|
ocapJson['capability']=capabilityList
|
||||||
|
|
||||||
try:
|
tries=0
|
||||||
with open(ocapFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
return True
|
with open(ocapFilename, 'w') as fp:
|
||||||
except Exception as e:
|
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
|
||||||
print(e)
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(1)
|
||||||
|
tries+=1
|
||||||
return False
|
return False
|
||||||
|
|
65
config.py
65
config.py
|
@ -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 = {
|
||||||
}
|
}
|
||||||
try:
|
tries=0
|
||||||
with open(configFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(configJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(configFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(configJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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'
|
||||||
try:
|
tries=0
|
||||||
with open(configFilename, 'r') as fp:
|
while tries<5:
|
||||||
configJson=commentjson.load(fp)
|
try:
|
||||||
except Exception as e:
|
with open(configFilename, 'r') as fp:
|
||||||
print(e)
|
configJson=commentjson.load(fp)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(1)
|
||||||
|
tries+=1
|
||||||
configJson[variableName]=variableValue
|
configJson[variableName]=variableValue
|
||||||
try:
|
tries=0
|
||||||
with open(configFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(configJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(configFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(configJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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'
|
||||||
try:
|
tries=0
|
||||||
with open(configFilename, 'r') as fp:
|
while tries<5:
|
||||||
configJson=commentjson.load(fp)
|
try:
|
||||||
if configJson.get(variableName):
|
with open(configFilename, 'r') as fp:
|
||||||
return configJson[variableName]
|
configJson=commentjson.load(fp)
|
||||||
except Exception as e:
|
if configJson.get(variableName):
|
||||||
print(e)
|
return configJson[variableName]
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(1)
|
||||||
|
tries+=1
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -322,7 +322,7 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||||
try:
|
try:
|
||||||
with open(baseDir+'/emoji/emoji.json', 'r') as fp:
|
with open(baseDir+'/emoji/emoji.json', 'r') as fp:
|
||||||
emojiDict=commentjson.load(fp)
|
emojiDict=commentjson.load(fp)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to load emoji: '+baseDir+'/emoji/emoji.json '+str(e))
|
print('Failed to load emoji: '+baseDir+'/emoji/emoji.json '+str(e))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
98
daemon.py
98
daemon.py
|
@ -1468,12 +1468,17 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if os.path.isfile(postFilename):
|
if os.path.isfile(postFilename):
|
||||||
postJsonObject={}
|
postJsonObject={}
|
||||||
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:
|
||||||
# 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
|
||||||
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:
|
||||||
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
|
||||||
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:
|
||||||
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
|
||||||
try:
|
tries=0
|
||||||
with open(postFilename, 'r') as fp:
|
while tries<5:
|
||||||
postJsonObject=commentjson.load(fp)
|
try:
|
||||||
readPost=True
|
with open(postFilename, 'r') as fp:
|
||||||
except Exception as e:
|
postJsonObject=commentjson.load(fp)
|
||||||
print(e)
|
readPost=True
|
||||||
|
break
|
||||||
|
except Exception as 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:
|
||||||
try:
|
tries=0
|
||||||
with open(actorFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(actorFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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'
|
||||||
try:
|
tries=0
|
||||||
with open(actorCacheFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(actorCacheFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(1)
|
||||||
|
tries+=1
|
||||||
# send actor update to followers
|
# send actor update to followers
|
||||||
updateActorJson={
|
updateActorJson={
|
||||||
'type': 'Update',
|
'type': 'Update',
|
||||||
|
|
16
follow.py
16
follow.py
|
@ -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'
|
||||||
try:
|
tries=0
|
||||||
with open(followActivityfilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(followJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
return True
|
with open(followActivityfilename, 'w') as fp:
|
||||||
except Exception as e:
|
commentjson.dump(followJson, fp, indent=4, sort_keys=False)
|
||||||
print(e)
|
return True
|
||||||
|
except Exception as 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, \
|
||||||
|
|
64
inbox.py
64
inbox.py
|
@ -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)
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(newQueueItem, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(newQueueItem, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(actorFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
print('actor updated for '+personJson['id'])
|
with open(actorFilename, 'w') as fp:
|
||||||
except Exception as e:
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
print(e)
|
print('actor updated for '+personJson['id'])
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(destinationFilename, 'w+') as fp:
|
while tries<5:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(destinationFilename, 'w+') as fp:
|
||||||
print(e)
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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):
|
||||||
try:
|
tries=0
|
||||||
with open(sharedInboxPostFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(queueJson['post'],fp,indent=4, \
|
try:
|
||||||
sort_keys=False)
|
with open(sharedInboxPostFilename, 'w') as fp:
|
||||||
except Exception as e:
|
commentjson.dump(queueJson['post'],fp,indent=4, \
|
||||||
print(e)
|
sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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():
|
||||||
|
|
30
like.py
30
like.py
|
@ -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'])
|
||||||
try:
|
tries=0
|
||||||
with open(postFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(postFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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)
|
||||||
try:
|
tries=0
|
||||||
with open(postFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(postFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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, \
|
||||||
|
|
|
@ -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
|
||||||
|
|
92
person.py
92
person.py
|
@ -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
|
||||||
try:
|
tries=0
|
||||||
with open(personFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(personFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(actorFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(actorFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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'
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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'
|
||||||
try:
|
tries=0
|
||||||
with open(cacheFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(cacheFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
|
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(1)
|
||||||
|
tries+=1
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
31
posts.py
31
posts.py
|
@ -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'
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(announceFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
try:
|
||||||
return postJsonObject
|
with open(announceFilename, 'w') as fp:
|
||||||
except Exception as e:
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
print(e)
|
return postJsonObject
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(1)
|
||||||
|
tries+=1
|
||||||
return None
|
return None
|
||||||
|
|
76
roles.py
76
roles.py
|
@ -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
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'r') as fp:
|
while tries<5:
|
||||||
actorJson=commentjson.load(fp)
|
try:
|
||||||
except Exception as e:
|
with open(filename, '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['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')
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
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:
|
||||||
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]
|
||||||
try:
|
tries=0
|
||||||
with open(actorFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(actorFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
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:
|
||||||
if not actorJson.get('roles'):
|
if not actorJson.get('roles'):
|
||||||
|
|
122
shares.py
122
shares.py
|
@ -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):
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'r') as fp:
|
while tries<5:
|
||||||
sharesJson=commentjson.load(fp)
|
try:
|
||||||
except Exception as e:
|
with open(sharesFilename, 'r') as fp:
|
||||||
print(e)
|
sharesJson=commentjson.load(fp)
|
||||||
|
break
|
||||||
|
except Exception as 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]
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(sharesFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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):
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'r') as fp:
|
while tries<5:
|
||||||
sharesJson=commentjson.load(fp)
|
try:
|
||||||
except Exception as e:
|
with open(sharesFilename, 'r') as fp:
|
||||||
print(e)
|
sharesJson=commentjson.load(fp)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(sharesFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'r') as fp:
|
while tries<5:
|
||||||
sharesJson=commentjson.load(fp)
|
try:
|
||||||
except Exception as e:
|
with open(sharesFilename, 'r') as fp:
|
||||||
print(e)
|
sharesJson=commentjson.load(fp)
|
||||||
|
break
|
||||||
|
except Exception as 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')
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(sharesFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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):
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'r') as fp:
|
while tries<5:
|
||||||
sharesJson=commentjson.load(fp)
|
try:
|
||||||
noOfShares=len(sharesJson.items())
|
with open(sharesFilename, 'r') as fp:
|
||||||
except Exception as e:
|
sharesJson=commentjson.load(fp)
|
||||||
print(e)
|
noOfShares=len(sharesJson.items())
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'r') as fp:
|
while tries<5:
|
||||||
sharesJson=commentjson.load(fp)
|
try:
|
||||||
except Exception as e:
|
with open(sharesFilename, 'r') as fp:
|
||||||
print(e)
|
sharesJson=commentjson.load(fp)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(1)
|
||||||
|
tries+=1
|
||||||
|
|
||||||
if sharesJson:
|
if sharesJson:
|
||||||
for itemID,item in sharesJson.items():
|
for itemID,item in sharesJson.items():
|
||||||
|
|
76
skills.py
76
skills.py
|
@ -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
|
||||||
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:
|
||||||
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]
|
||||||
try:
|
tries=0
|
||||||
with open(actorFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(actorFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
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['skills']=skills
|
actorJson['skills']=skills
|
||||||
try:
|
tries=0
|
||||||
with open(actorFilename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(actorFilename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
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:
|
||||||
if not actorJson.get('skills'):
|
if not actorJson.get('skills'):
|
||||||
|
|
30
webfinger.py
30
webfinger.py
|
@ -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'
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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'
|
||||||
try:
|
tries=0
|
||||||
with open(filename, 'w') as fp:
|
while tries<5:
|
||||||
commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
except Exception as e:
|
with open(filename, 'w') as fp:
|
||||||
print(e)
|
commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
|
||||||
|
break
|
||||||
|
except Exception as 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, \
|
||||||
|
|
167
webinterface.py
167
webinterface.py
|
@ -150,12 +150,17 @@ def htmlSearchEmoji(translate: {},baseDir: str,searchStr: str) -> str:
|
||||||
return emojiForm
|
return emojiForm
|
||||||
|
|
||||||
loadedEmoji=False
|
loadedEmoji=False
|
||||||
try:
|
tries=0
|
||||||
with open(emojiLookupFilename, 'r') as fp:
|
while tries<5:
|
||||||
emojiJson=commentjson.load(fp)
|
try:
|
||||||
loadedEmoji=True
|
with open(emojiLookupFilename, 'r') as fp:
|
||||||
except Exception as e:
|
emojiJson=commentjson.load(fp)
|
||||||
print(e)
|
loadedEmoji=True
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
try:
|
tries=0
|
||||||
with open(sharesFilename, 'r') as fp:
|
while tries<5:
|
||||||
sharesJson=commentjson.load(fp)
|
try:
|
||||||
except Exception as e:
|
with open(sharesFilename, 'r') as fp:
|
||||||
print(e)
|
sharesJson=commentjson.load(fp)
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
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 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
|
||||||
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:
|
||||||
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
|
||||||
try:
|
tries=0
|
||||||
with open(actorFilename, 'r') as fp:
|
while tries<5:
|
||||||
cachedActorJson=commentjson.load(fp)
|
try:
|
||||||
loadedActor=True
|
with open(actorFilename, 'r') as fp:
|
||||||
except Exception as e:
|
cachedActorJson=commentjson.load(fp)
|
||||||
print(e)
|
loadedActor=True
|
||||||
|
break
|
||||||
|
except Exception as 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
|
||||||
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:
|
||||||
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
|
||||||
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:
|
||||||
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
|
||||||
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:
|
||||||
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
|
||||||
try:
|
while tries<5:
|
||||||
with open(sharesFile, 'r') as fp:
|
try:
|
||||||
sharesJson=commentjson.load(fp)
|
with open(sharesFile, 'r') as fp:
|
||||||
except Exception as e:
|
sharesJson=commentjson.load(fp)
|
||||||
print(e)
|
break
|
||||||
|
except Exception as 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
|
||||||
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 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'):
|
||||||
|
|
Loading…
Reference in New Issue