Refactor __main__

This commit is contained in:
Kristóf Tóth 2018-02-24 21:03:36 +01:00
parent 461fd8e8f0
commit 37d418bda4

View File

@ -49,13 +49,18 @@ class imgrate:
if __name__ == '__main__': if __name__ == '__main__':
def parse_arguments():
ap = ArgumentParser() ap = ArgumentParser()
ap.add_argument('images', type=str, nargs='+', help='') ap.add_argument('images', type=str, nargs='+', help='')
args = ap.parse_args() return ap.parse_args()
def run(args):
ratings = {image: imgrate(image).quality for image in args.images} ratings = {image: imgrate(image).quality for image in args.images}
maximum = max(ratings, key=ratings.get) maximum = max(ratings, key=ratings.get)
for rating in ratings.keys(): for rating in ratings.keys():
maxmark = '*' if rating == maximum and len(ratings) > 1 else ' ' maxmark = '*' if rating == maximum and len(ratings) > 1 else ' '
print('{}imgrate("{}") = {}'.format(maxmark, rating, ratings[rating])) print('{}imgrate("{}") = {}'.format(maxmark, rating, ratings[rating]))
run(parse_arguments())