1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-09-11 16:22:24 +02:00

Refactor get_filename

Use string formatting instead of `str(0) + str(index)` and don't assume file extension is three characters.
This commit is contained in:
Lars Lindqvist 2019-01-08 19:38:46 +01:00 committed by GitHub
parent d2bebcd00c
commit c54342bb98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -255,8 +255,7 @@ class Instaloader:
return None
else:
def get_filename(index):
return filename if index == 0 else (filename[:-4] + '_old_' +
(str(0) if index < 10 else str()) + str(index) + filename[-4:])
return filename if index == 0 else '{0}_old_{2:02}{1}'.format(*os.path.splitext(filename), index)
i = 0
while os.path.isfile(get_filename(i)):