prepend to follow/followers files

main2
Bob Mottram 2019-10-26 16:15:38 +01:00
parent a65b8bf644
commit 841367fa76
2 changed files with 18 additions and 8 deletions

View File

@ -505,9 +505,13 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
print('Updating followers file: '+followersFilename+' adding '+approveHandle)
if os.path.isfile(followersFilename):
if approveHandle not in open(followersFilename).read():
followersFile=open(followersFilename, "a+")
followersFile.write(approveHandle+'\n')
followersFile.close()
try:
with open(followersFilename, 'r+') as followersFile:
content = followersFile.read()
followersFile.seek(0, 0)
followersFile.write(approveHandle+'\n'+content)
except Exception as e:
print('WARN: Failed to write entry to followers file '+str(e))
else:
followersFile=open(followersFilename, "w+")
followersFile.write(approveHandle+'\n')

View File

@ -219,11 +219,17 @@ def followPerson(baseDir: str,nickname: str, domain: str, \
if debug:
print('DEBUG: follow already exists')
return True
with open(filename, "a") as followfile:
followfile.write(followNickname+'@'+followDomain+'\n')
if debug:
print('DEBUG: follow added')
return True
# prepend to follow file
try:
with open(filename, 'r+') as followFile:
content = followFile.read()
followFile.seek(0, 0)
followFile.write(followNickname+'@'+followDomain+'\n'+content)
if debug:
print('DEBUG: follow added')
return True
except Exception as e:
print('WARN: Failed to write entry to follow file '+filename+' '+str(e))
if debug:
print('DEBUG: creating new following file')
with open(filename, "w") as followfile: