From 907bfa350847ce299319b98340802bcf7b25f974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rostislav=20L=C3=A1n?= Date: Tue, 22 Nov 2022 16:32:43 +0100 Subject: [PATCH] Changed argument parsing to method. --- src/main.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main.py b/src/main.py index 6b8016e..a75b13a 100644 --- a/src/main.py +++ b/src/main.py @@ -12,27 +12,25 @@ import matplotlib.pyplot as plt # Import custom image filter library import filters as flt -parser = ap.ArgumentParser(prog='main.py', - description='loads and stores image') - -parser.add_argument("-i", "--input_file", help="Input file", required=True) -parser.add_argument("-o", "--output_file", help="Output file", required=True) -parser.add_argument('-d', "--dpi", type=int, required=True) -#parser.add_argument( '-s', '--size') -parser.add_argument('filters', type=str, nargs='*') - -args = parser.parse_args() - - class app: - def __init__(self, input_file, output_file, dpi, filters): - self.input_file = input_file - self.output_file = output_file + def __init__(self): + self.parse_arguments() + self.input_file = self.args.input_file + self.output_file = self.args.output_file self.img = plt.imread(self.input_file) - self.dpi = dpi - self.filters = filters + self.dpi = self.args.dpi + self.filters = self.args.filters self.apply_filters() + def parse_arguments(self): + parser = ap.ArgumentParser(prog='main.py', description='loads and stores image') + parser.add_argument("-i", "--input_file", help="Input file", required=True) + parser.add_argument("-o", "--output_file", help="Output file", required=True) + parser.add_argument('-d', "--dpi", type=int, required=True) + #parser.add_argument( '-s', '--size') + parser.add_argument('filters', type=str, nargs='*') + self.args = parser.parse_args() + def filter_factory(self, filter_name): if filter_name == "average": return flt.filter_average @@ -53,5 +51,4 @@ class app: # Save processed image plt.savefig(self.output_file) - -app = app(args.input_file, args.output_file, args.dpi, args.filters) +app = app()