|
3 | 3 |
|
4 | 4 | # Standard Imports |
5 | 5 | import argparse |
| 6 | +import ast |
6 | 7 | import os |
7 | 8 | import logging |
8 | 9 | from distutils.util import strtobool |
|
18 | 19 | parser.add_argument("-p", "--product", help="Example: adaptation_detail", required=True) |
19 | 20 | parser.add_argument("-api_key", "--api_key", required=False) |
20 | 21 | parser.add_argument("-v", "--version", required=False) |
21 | | - parser.add_argument("-i", "--fsids", help="Example: 28,29", required=False,) |
| 22 | + parser.add_argument("-i", "--search_items", help="Example: 28,29", required=False,) |
22 | 23 | parser.add_argument("-l", "--location", help="Example: property", required=False) |
23 | 24 | parser.add_argument("-limit", "--limit", help="Example: 100", required=False, default="100") |
24 | 25 | parser.add_argument("-log", "--log", help="Example: False", required=False, default="True") |
25 | 26 | parser.add_argument("-f", "--file", help="Example: ./sample.txt", required=False) |
26 | 27 |
|
27 | 28 | argument = parser.parse_args() |
28 | 29 |
|
29 | | - # Merge FSIDs from file and list input |
30 | | - fsids = [] |
31 | | - if argument.fsids: |
32 | | - try: |
33 | | - fsids += list(map(int, argument.fsids.strip().split(","))) |
34 | | - except ValueError: |
35 | | - logging.warning("An invalid fsid list was provided. Please check this input list is a comma-separated " |
36 | | - "list of integers: '{}'".format(argument.fsids)) |
| 30 | + # Merge search_item from file and list input |
| 31 | + search_items = [] |
| 32 | + if argument.search_items: |
| 33 | + for search_item in argument.search_items.strip().split(";"): |
| 34 | + try: |
| 35 | + search_items.append(ast.literal_eval(search_item)) |
| 36 | + except (SyntaxError, ValueError): |
| 37 | + search_items.append(search_item) |
37 | 38 |
|
38 | 39 | if argument.file: |
39 | | - fsids += read_search_items_from_file(argument.file) |
| 40 | + search_items += read_search_items_from_file(argument.file) |
40 | 41 |
|
41 | | - # Ensure there is at least a product and FSID |
42 | | - if fsids: |
| 42 | + # Ensure there is at least a product and search item |
| 43 | + if search_items: |
43 | 44 |
|
44 | 45 | # Try to get the API key either from env var or the parameter |
45 | 46 | if not argument.api_key: |
|
57 | 58 | limit = int(argument.limit) |
58 | 59 |
|
59 | 60 | if argument.product == 'adaptation.get_detail': |
60 | | - fs.adaptation.get_detail(fsids, csv=True, limit=limit) |
| 61 | + fs.adaptation.get_detail(search_items, csv=True, limit=limit) |
61 | 62 |
|
62 | 63 | elif argument.product == 'adaptation.get_summary': |
63 | | - fs.adaptation.get_summary(fsids, argument.location, csv=True, limit=limit) |
| 64 | + fs.adaptation.get_summary(search_items, argument.location, csv=True, limit=limit) |
64 | 65 |
|
65 | 66 | elif argument.product == 'adaptation.get_details_by_location': |
66 | | - fs.adaptation.get_details_by_location(fsids, argument.location, csv=True, limit=limit) |
| 67 | + fs.adaptation.get_details_by_location(search_items, argument.location, csv=True, limit=limit) |
67 | 68 |
|
68 | 69 | elif argument.product == 'probability.get_depth': |
69 | | - fs.probability.get_depth(fsids, csv=True, limit=limit) |
| 70 | + fs.probability.get_depth(search_items, csv=True, limit=limit) |
70 | 71 |
|
71 | 72 | elif argument.product == 'probability.get_chance': |
72 | | - fs.probability.get_chance(fsids, csv=True, limit=limit) |
| 73 | + fs.probability.get_chance(search_items, csv=True, limit=limit) |
73 | 74 |
|
74 | 75 | elif argument.product == 'probability.get_count_summary': |
75 | | - fs.probability.get_count_summary(fsids, csv=True, limit=limit) |
| 76 | + fs.probability.get_count_summary(search_items, csv=True, limit=limit) |
76 | 77 |
|
77 | 78 | elif argument.product == 'probability.get_cumulative': |
78 | | - fs.probability.get_cumulative(fsids, csv=True, limit=limit) |
| 79 | + fs.probability.get_cumulative(search_items, csv=True, limit=limit) |
79 | 80 |
|
80 | 81 | elif argument.product == 'probability.get_count': |
81 | | - fs.probability.get_count(fsids, argument.location, csv=True, limit=limit) |
| 82 | + fs.probability.get_count(search_items, argument.location, csv=True, limit=limit) |
82 | 83 |
|
83 | 84 | elif argument.product == 'historic.get_event': |
84 | | - fs.historic.get_event(fsids, csv=True, limit=limit) |
| 85 | + fs.historic.get_event(search_items, csv=True, limit=limit) |
85 | 86 |
|
86 | 87 | elif argument.product == 'historic.get_summary': |
87 | | - fs.historic.get_summary(fsids, argument.location, csv=True, limit=limit) |
| 88 | + fs.historic.get_summary(search_items, argument.location, csv=True, limit=limit) |
88 | 89 |
|
89 | 90 | elif argument.product == 'historic.get_events_by_location': |
90 | | - fs.historic.get_events_by_location(fsids, argument.location, csv=True, limit=limit) |
| 91 | + fs.historic.get_events_by_location(search_items, argument.location, csv=True, limit=limit) |
91 | 92 |
|
92 | 93 | elif argument.product == 'location.get_detail': |
93 | | - fs.location.get_detail(fsids, argument.location, csv=True, limit=limit) |
| 94 | + fs.location.get_detail(search_items, argument.location, csv=True, limit=limit) |
94 | 95 |
|
95 | 96 | elif argument.product == 'location.get_summary': |
96 | | - fs.location.get_summary(fsids, argument.location, csv=True, limit=limit) |
| 97 | + fs.location.get_summary(search_items, argument.location, csv=True, limit=limit) |
97 | 98 |
|
98 | 99 | elif argument.product == 'fema.get_nfip': |
99 | | - fs.fema.get_nfip(fsids, argument.location, csv=True, limit=limit) |
| 100 | + fs.fema.get_nfip(search_items, argument.location, csv=True, limit=limit) |
100 | 101 |
|
101 | 102 | elif argument.product == 'environmental.get_precipitation': |
102 | | - fs.environmental.get_precipitation(fsids, csv=True, limit=limit) |
| 103 | + fs.environmental.get_precipitation(search_items, csv=True, limit=limit) |
103 | 104 |
|
104 | 105 | else: |
105 | 106 | logging.error("Product not found. Please check that the argument" |
106 | 107 | " provided is correct: {}".format(argument.product)) |
107 | 108 |
|
108 | 109 | else: |
109 | | - raise InvalidArgument("No fsids were provided from either a fsid list or a file. " |
110 | | - "List: '{}', File Name: '{}'".format(argument.fsids, argument.file)) |
| 110 | + raise InvalidArgument("No search items were provided from either a search item list or a file. " |
| 111 | + "List: '{}', File Name: '{}'".format(argument.search_items, argument.file)) |
0 commit comments