Conditions | 3 |
Total Lines | 52 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | #!/usr/bin/python |
||
14 | def run_application(): |
||
15 | """Run SauceNao based on arguments passed to the file |
||
16 | |||
17 | :return: |
||
18 | """ |
||
19 | parser = argparse.ArgumentParser() |
||
20 | parser.add_argument('-d', '--dir', help='directory to sort', required=True) |
||
21 | parser.add_argument('-db', '--databases', default=999, type=int, help='which databases should be searched') |
||
22 | parser.add_argument('-min', '--minimum-similarity', default=65, type=float, |
||
23 | help='minimum similarity percentage') |
||
24 | parser.add_argument('-c', '--combine-api-types', action='store_true', |
||
25 | help='combine html and json api response to retrieve more information') |
||
26 | parser.add_argument('-k', '--api-key', help='API key of your account on SauceNao') |
||
27 | parser.add_argument('-x', '--exclude-categories', type=str, help='exclude specific categories from moving') |
||
28 | parser.add_argument('-mv', '--move-to-categories', action='store_true', help='move images to categories') |
||
29 | parser.add_argument('-author', '--use-author-as-category', default=False, action='store_true', |
||
30 | help='use author as category key instead of material') |
||
31 | parser.add_argument('-o', '--output-type', default=0, type=int, help='0(html) or 2(json) API response') |
||
32 | parser.add_argument('-sf', '--start-file', |
||
33 | help='with which file the checks start in case of after reaching the daily limit') |
||
34 | parser.add_argument('-log', '--log-level', default=logging.ERROR, type=int, |
||
35 | help='which log level should be used, check logging._levelNames for options') |
||
36 | |||
37 | parser.add_argument('-fcrdt', '--filter-creation-date', type=str, |
||
38 | help='filters files for created after given date. ' |
||
39 | 'Format of date has to match "d.m.Y[ H:M[:S]]"') |
||
40 | parser.add_argument('-fmdt', '--filter-modified-date', type=str, |
||
41 | help='filters files for modified after given date. ' |
||
42 | 'Format of date has to match "d.m.Y[ H:M[:S]]"') |
||
43 | |||
44 | parser.add_argument('-tmin', '--title-minimum-similarity', default=95, type=float, |
||
45 | help='minimum similarity percentage for title search with BakaUpdates, MyAnimeList and ' |
||
46 | 'VisualNovelDatabase') |
||
47 | |||
48 | args = parser.parse_args() |
||
49 | |||
50 | file_filter = Filter(assert_is_file=True) |
||
51 | if args.filter_creation_date: |
||
52 | file_filter._filter_creation_date = Constraint(value=args.filter_creation_date, |
||
53 | cmp_func=Constraint.cmp_value_bigger_or_equal) |
||
54 | if args.filter_modified_date: |
||
55 | file_filter._filter_modified_date = Constraint(value=args.filter_modified_date, |
||
56 | cmp_func=Constraint.cmp_value_bigger_or_equal) |
||
57 | working_files = FileHandler.get_files(args.dir, file_filter) |
||
58 | |||
59 | saucenao_worker = Worker(files=working_files, directory=args.dir, databases=args.databases, |
||
60 | minimum_similarity=args.minimum_similarity, combine_api_types=args.combine_api_types, |
||
61 | api_key=args.api_key, exclude_categories=args.exclude_categories, |
||
62 | move_to_categories=args.move_to_categories, |
||
63 | use_author_as_category=args.use_author_as_category, start_file=args.start_file, |
||
64 | log_level=args.log_level, title_minimum_similarity=args.title_minimum_similarity) |
||
65 | return saucenao_worker.run() |
||
66 |