From 667d0262eae68d2e67c81840b57c1d5fc6a669f3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 5 Nov 2019 13:13:55 +0000 Subject: [PATCH] Prepend to followers file --- manualapprove.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/manualapprove.py b/manualapprove.py index 055d09015..fb05cb9b6 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -128,9 +128,13 @@ def manualApproveFollowRequest(session,baseDir: str, \ followersFilename=accountsDir+'/followers.txt' 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')