From bf828bbac5ca409033ae73025d9b4e0fe540b9a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 24 Feb 2018 21:08:17 +0100 Subject: [PATCH] Add CLI flag --delete --- imgrate.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/imgrate.py b/imgrate.py index 67ab8cf..0ea5d90 100755 --- a/imgrate.py +++ b/imgrate.py @@ -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())