flake8 format

main
Bob Mottram 2020-04-03 17:01:25 +00:00
parent 295814cd9b
commit 08a1b05a76
1 changed files with 24 additions and 21 deletions

View File

@ -1,50 +1,53 @@
__filename__="migrate.py" __filename__ = "migrate.py"
__author__="Bob Mottram" __author__ = "Bob Mottram"
__license__="AGPL3+" __license__ = "AGPL3+"
__version__="1.1.0" __version__ = "1.1.0"
__maintainer__="Bob Mottram" __maintainer__ = "Bob Mottram"
__email__="bob@freedombone.net" __email__ = "bob@freedombone.net"
__status__="Production" __status__ = "Production"
import os import os
def migrateFollows(followFilename: str,oldHandle: str,newHandle: str) -> None:
def migrateFollows(followFilename: str, oldHandle: str,
newHandle: str) -> None:
"""Changes a handle within following or followers list """Changes a handle within following or followers list
""" """
if not os.path.isfile(followFilename): if not os.path.isfile(followFilename):
return return
if oldHandle not in open(followFilename).read(): if oldHandle not in open(followFilename).read():
return return
followData=None followData = None
with open(followFilename, 'r') as followFile: with open(followFilename, 'r') as followFile:
followData=followFile.read() followData = followFile.read()
if not followData: if not followData:
return return
newFollowData=followData.replace(oldHandle,newHandle) newFollowData = followData.replace(oldHandle, newHandle)
if followData==newFollowData: if followData == newFollowData:
return return
with open(followFilename, 'w') as followFile: with open(followFilename, 'w') as followFile:
followFile.write(newFollowData) followFile.write(newFollowData)
def migrateAccount(baseDir: str,oldHandle: str,newHandle: str) -> None:
def migrateAccount(baseDir: str, oldHandle: str, newHandle: str) -> None:
"""If a followed account changes then this modifies the """If a followed account changes then this modifies the
following and followers lists for each account accordingly following and followers lists for each account accordingly
""" """
if oldHandle.startswith('@'): if oldHandle.startswith('@'):
oldHandle=oldHandle[1:] oldHandle = oldHandle[1:]
if '@' not in oldHandle: if '@' not in oldHandle:
return return
if newHandle.startswith('@'): if newHandle.startswith('@'):
ewHandle=newHandle[1:] newHandle = newHandle[1:]
if '@' not in newHandle: if '@' not in newHandle:
return return
# update followers and following lists for each account # update followers and following lists for each account
for subdir, dirs, files in os.walk(baseDir+'/accounts'): for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for handle in dirs: for handle in dirs:
if '@' in handle: if '@' in handle:
accountDir=baseDir+'/accounts/'+handle accountDir = baseDir + '/accounts/' + handle
followFilename=accountDir+'/following.txt' followFilename = accountDir + '/following.txt'
migrateFollows(followFilename,oldHandle,newHandle) migrateFollows(followFilename, oldHandle, newHandle)
followFilename=accountDir+'/followers.txt' followFilename = accountDir + '/followers.txt'
migrateFollows(followFilename,oldHandle,newHandle) migrateFollows(followFilename, oldHandle, newHandle)