|
19 | 19 | parser.add_argument("-p", "--product", help="Example: adaptation_detail", required=True) |
20 | 20 | parser.add_argument("-api_key", "--api_key", required=False) |
21 | 21 | parser.add_argument("-v", "--version", required=False) |
22 | | - parser.add_argument("-i", "--search_items", help="Example: 28,29", required=False,) |
23 | | - parser.add_argument("-l", "--location", help="Example: property", required=False) |
| 22 | + # Convert log default to an actual boolean |
| 23 | + parser.add_argument("-log", "--log", help="Example: False", required=False, default="True") |
24 | 24 | parser.add_argument("-connection_limit", "--connection_limit", help="Example: 100", required=False, default="100") |
25 | 25 | parser.add_argument("-rate_limit", "--rate_limit", help="Example: 5000", required=False, default="20000") |
26 | 26 | parser.add_argument("-rate_period", "--rate_period", help="Example: 3600", required=False, default="1") |
27 | | - parser.add_argument("-log", "--log", help="Example: False", required=False, default="True") |
| 27 | + parser.add_argument("-o", "--output_dir", help="Example: /output", required=False) |
| 28 | + parser.add_argument("-s", "--search_items", help="Example: 28,29", required=False,) |
| 29 | + parser.add_argument("-l", "--location_type", help="Example: property", required=False) |
| 30 | + parser.add_argument("-y", "--year", required=False) |
| 31 | + parser.add_argument("-rp", "--return_period", required=False) |
| 32 | + parser.add_argument("-eid", "--event_id", required=False) |
| 33 | + # deprecated file parameter. Will be removed in a later version |
28 | 34 | parser.add_argument("-f", "--file", help="Example: ./sample.txt", required=False) |
| 35 | + # deprecated extra_param parameter. Will be removed in a later version |
29 | 36 | parser.add_argument("-e", "--extra_param", required=False) |
30 | | - parser.add_argument("-year", "--year", required=False) |
31 | | - parser.add_argument("-return_period", "--return_period", required=False) |
32 | | - parser.add_argument("-event_id", "--event_id", required=False) |
33 | 37 |
|
34 | 38 | argument = parser.parse_args() |
35 | 39 |
|
36 | | - # Merge search_item from file and list input |
| 40 | + # Reads a file or converts search items into a list |
37 | 41 | search_items = [] |
38 | 42 | if argument.search_items: |
39 | | - for search_item in argument.search_items.strip().split(";"): |
40 | | - try: |
41 | | - search_items.append(ast.literal_eval(search_item)) |
42 | | - except (SyntaxError, ValueError): |
43 | | - search_items.append(search_item) |
| 43 | + |
| 44 | + # If file, read addresses from file |
| 45 | + if os.path.isfile(argument.search_items): |
| 46 | + search_items = read_search_items_from_file(argument.search_items) |
| 47 | + else: |
| 48 | + for search_item in argument.search_items.strip().split(";"): |
| 49 | + try: |
| 50 | + search_items.append(ast.literal_eval(search_item)) |
| 51 | + except (SyntaxError, ValueError): |
| 52 | + search_items.append(search_item) |
44 | 53 |
|
45 | 54 | if argument.file: |
| 55 | + logging.warning("'file' argument deprecated and will be removed. Use `-s path_to_file` instead. " |
| 56 | + "Ex: `-s testing/sample.txt`") |
46 | 57 | search_items += read_search_items_from_file(argument.file) |
47 | 58 |
|
48 | 59 | # Ensure there is at least a product and search item |
|
70 | 81 | if argument.product == 'adaptation.get_detail': |
71 | 82 | fs.adaptation.get_detail(search_items, |
72 | 83 | csv=True, |
| 84 | + output_dir=argument.output_dir, |
73 | 85 | extra_param=argument.extra_param) |
74 | 86 |
|
75 | 87 | elif argument.product == 'adaptation.get_summary': |
76 | 88 | fs.adaptation.get_summary(search_items, |
77 | | - argument.location, |
| 89 | + argument.location_type, |
78 | 90 | csv=True, |
| 91 | + output_dir=argument.output_dir, |
79 | 92 | extra_param=argument.extra_param) |
80 | 93 |
|
81 | | - elif argument.product == 'adaptation.get_details_by_location': |
82 | | - fs.adaptation.get_details_by_location(search_items, |
83 | | - argument.location, |
84 | | - csv=True, |
85 | | - extra_param=argument.extra_param) |
| 94 | + elif argument.product == 'adaptation.get_detail_by_location': |
| 95 | + fs.adaptation.get_detail_by_location(search_items, |
| 96 | + argument.location_type, |
| 97 | + csv=True, |
| 98 | + output_dir=argument.output_dir, |
| 99 | + extra_param=argument.extra_param) |
86 | 100 |
|
87 | 101 | elif argument.product == 'probability.get_depth': |
88 | 102 | fs.probability.get_depth(search_items, |
89 | 103 | csv=True, |
| 104 | + output_dir=argument.output_dir, |
90 | 105 | extra_param=argument.extra_param) |
91 | 106 |
|
92 | 107 | elif argument.product == 'probability.get_chance': |
93 | 108 | fs.probability.get_chance(search_items, |
94 | 109 | csv=True, |
| 110 | + output_dir=argument.output_dir, |
95 | 111 | extra_param=argument.extra_param) |
96 | 112 |
|
97 | 113 | elif argument.product == 'probability.get_count_summary': |
98 | 114 | fs.probability.get_count_summary(search_items, |
99 | 115 | csv=True, |
| 116 | + output_dir=argument.output_dir, |
100 | 117 | extra_param=argument.extra_param) |
101 | 118 |
|
102 | 119 | elif argument.product == 'probability.get_cumulative': |
103 | 120 | fs.probability.get_cumulative(search_items, |
104 | 121 | csv=True, |
| 122 | + output_dir=argument.output_dir, |
105 | 123 | extra_param=argument.extra_param) |
106 | 124 |
|
107 | 125 | elif argument.product == 'probability.get_count': |
108 | 126 | fs.probability.get_count(search_items, |
109 | | - argument.location, |
| 127 | + argument.location_type, |
110 | 128 | csv=True, |
| 129 | + output_dir=argument.output_dir, |
111 | 130 | extra_param=argument.extra_param) |
112 | 131 |
|
113 | 132 | elif argument.product == 'historic.get_event': |
114 | 133 | fs.historic.get_event(search_items, |
115 | 134 | csv=True, |
| 135 | + output_dir=argument.output_dir, |
116 | 136 | extra_param=argument.extra_param) |
117 | 137 |
|
118 | 138 | elif argument.product == 'historic.get_summary': |
119 | 139 | fs.historic.get_summary(search_items, |
120 | | - argument.location, |
| 140 | + argument.location_type, |
121 | 141 | csv=True, |
| 142 | + output_dir=argument.output_dir, |
122 | 143 | extra_param=argument.extra_param) |
123 | 144 |
|
124 | 145 | elif argument.product == 'historic.get_events_by_location': |
125 | 146 | fs.historic.get_events_by_location(search_items, |
126 | | - argument.location, |
| 147 | + argument.location_type, |
127 | 148 | csv=True, |
| 149 | + output_dir=argument.output_dir, |
128 | 150 | extra_param=argument.extra_param) |
129 | 151 |
|
130 | 152 | elif argument.product == 'location.get_detail': |
131 | 153 | fs.location.get_detail(search_items, |
132 | | - argument.location, |
| 154 | + argument.location_type, |
133 | 155 | csv=True, |
| 156 | + output_dir=argument.output_dir, |
134 | 157 | extra_param=argument.extra_param) |
135 | 158 |
|
136 | 159 | elif argument.product == 'location.get_summary': |
137 | 160 | fs.location.get_summary(search_items, |
138 | | - argument.location, |
| 161 | + argument.location_type, |
139 | 162 | csv=True, |
| 163 | + output_dir=argument.output_dir, |
140 | 164 | extra_param=argument.extra_param) |
141 | 165 |
|
142 | 166 | elif argument.product == 'fema.get_nfip': |
143 | 167 | fs.fema.get_nfip(search_items, |
144 | | - argument.location, |
| 168 | + argument.location_type, |
145 | 169 | csv=True, |
| 170 | + output_dir=argument.output_dir, |
146 | 171 | extra_param=argument.extra_param) |
147 | 172 |
|
148 | 173 | elif argument.product == 'environmental.get_precipitation': |
149 | 174 | fs.environmental.get_precipitation(search_items, |
150 | 175 | csv=True, |
| 176 | + output_dir=argument.output_dir, |
151 | 177 | extra_param=argument.extra_param) |
152 | 178 |
|
153 | 179 | elif argument.product == 'tile.get_probability_depth': |
154 | | - fs.tile.get_probability_depth(year=int(argument.year), return_period=int(argument.return_period), |
155 | | - coordinate=search_items, |
| 180 | + fs.tile.get_probability_depth(year=int(argument.year), |
| 181 | + return_period=int(argument.return_period), |
| 182 | + search_items=search_items, |
| 183 | + output_dir=argument.output_dir, |
156 | 184 | image=True) |
157 | 185 |
|
158 | 186 | elif argument.product == 'tile.get_historic_event': |
159 | | - fs.tile.get_historic_event(event_id=int(argument.event_id), coordinate=search_items, |
| 187 | + fs.tile.get_historic_event(event_id=int(argument.event_id), |
| 188 | + search_items=search_items, |
| 189 | + output_dir=argument.output_dir, |
160 | 190 | image=True) |
161 | 191 |
|
162 | | - # AND FILES |
163 | | - |
164 | 192 | else: |
165 | 193 | logging.error("Product not found. Please check that the argument" |
166 | 194 | " provided is correct: {}".format(argument.product)) |
|
0 commit comments