Add CLI flag --delete

This commit is contained in:
Kristóf Tóth 2018-02-24 21:08:17 +01:00
parent 37d418bda4
commit bf828bbac5

View File

@ -49,9 +49,12 @@ class imgrate:
if __name__ == '__main__':
from os import remove
def parse_arguments():
ap = ArgumentParser()
ap.add_argument('images', type=str, nargs='+', help='')
ap.add_argument('-d', '--delete', action='store_true', help='Delete all but the best quality image.')
return ap.parse_args()
@ -63,4 +66,8 @@ if __name__ == '__main__':
maxmark = '*' if rating == maximum and len(ratings) > 1 else ' '
print('{}imgrate("{}") = {}'.format(maxmark, rating, ratings[rating]))
if args.delete:
[remove(image) for image in ratings if image != maximum]
run(parse_arguments())