Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit f8e6274

Browse files
committed
Add file line skip if invalid and API key to CLI
1 parent 9bc98bb commit f8e6274

8 files changed

+572
-7
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
5151

5252
2. Call one of the methods described below in the `Products` section. See the `Examples` section for examples.
5353
```python
54-
fs.<product>.<product_subtype>(<fsids>, <lookup_type>)
54+
fs.<product>.<product_subtype>(<fsids: list>, <lookup_type: string>)
5555
```
5656

5757
## Method 2: Through the Command Line
@@ -69,8 +69,18 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
6969

7070
- `-p/--product PRODUCT`: [REQUIRED] The product to call from the API
7171
- `[-i/--fsids FSIDS]`: [OPTIONAL] The FSIDs to search for with the product
72-
- `[-f/--file FILE]`: [OPTIONAL] A file of FSIDs (one per line) to search for with the product
7372
- `[-l/--location LOOKUP_TYPE]`: [OPTIONAL] The lookup location type (property, neighborhood, city, zcta, tract, county, cd, state)
73+
- `[-f/--file FILE]`: [OPTIONAL] A file of FSIDs (one per line) to search for with the product
74+
75+
Content of a sample text file:
76+
```text
77+
541114211
78+
540456284
79+
541229206
80+
540563324
81+
541262690
82+
540651172
83+
```
7484

7585
## Products
7686
### Location

firststreet/__main__.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
# Author: Kelvin Lai <kelvin@firststreet.org>
2+
# Copyright: This module is owned by First Street Foundation
3+
4+
# Standard Imports
15
import argparse
26
import os
7+
import logging
8+
9+
# Internal Imports
10+
import sys
311

412
import firststreet
13+
from firststreet import MissingAPIKeyError
14+
from firststreet.util import read_fsid_file
515

616
if __name__ == "__main__":
717
parser = argparse.ArgumentParser(description="Description for my parser")
18+
parser.add_argument("-a", "--api_key", required=False, default="")
819
parser.add_argument("-p", "--product", help="Example: adaptation_detail", required=True, default="")
920
parser.add_argument("-i", "--fsids", help="Example: 28,29", required=False, default="")
1021
parser.add_argument("-l", "--location", help="Example: property", required=False, default="")
@@ -17,13 +28,20 @@
1728
fsids += list(map(int, argument.fsids.strip().split(",")))
1829

1930
if argument.file:
20-
with open(argument.file) as fp:
21-
for line in fp:
22-
fsids.append(int(line.rstrip('\n')))
31+
fsids += read_fsid_file(argument.file)
2332

2433
if argument.product and fsids:
2534

26-
api_key = os.environ['FSF_API_KEY']
35+
if not argument.api_key:
36+
env_var_name = 'FSF_APfI_KEY'
37+
try:
38+
api_key = os.environ[env_var_name]
39+
except KeyError:
40+
logging.error("`{}` is not set as an Environmental Variable".format(env_var_name))
41+
sys.exit()
42+
else:
43+
api_key = argument.api_key
44+
2745
fs = firststreet.FirstStreet(api_key)
2846

2947
if argument.product == 'adaptation.get_detail':
@@ -66,4 +84,5 @@
6684
fs.environmental.get_precipitation(fsids, csv=True)
6785

6886
else:
69-
print("Product not found")
87+
logging.error("Product not found. Please check that the argument"
88+
" provided is correct: {}".format(argument.product))
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
fsid,adaptation
2+
541114211,
3+
540456284,
4+
541229206,
5+
540563324,
6+
541262690,
7+
540651172,
8+
540321926,
9+
541397402,
10+
540835968,
11+
540951325,
12+
540695623,
13+
541245323,
14+
540039428,
15+
540611506,
16+
540451980,
17+
540206660,
18+
541247265,
19+
540793246,
20+
540706732,
21+
540629760,
22+
541008337,
23+
541389052,
24+
540419962,
25+
541268364,
26+
541296035,
27+
541034820,
28+
540151216,
29+
540397030,
30+
541156316,
31+
540886492,
32+
541168970,
33+
541228788,
34+
541082842,
35+
541277095,2687
36+
540635265,
37+
540924465,
38+
540179113,
39+
540368183,
40+
540802128,
41+
540157051,
42+
540599292,
43+
540701698,
44+
541127065,
45+
540381378,
46+
540941201,
47+
540478428,
48+
540608643,
49+
541214101,
50+
541004243,
51+
540805761,
52+
540665287,
53+
541328658,
54+
541335961,
55+
540256544,
56+
540407071,
57+
541312162,
58+
541145330,
59+
540315374,
60+
540788900,
61+
540147226,
62+
540040622,
63+
540768481,
64+
541384755,
65+
540357885,
66+
540515000,6
67+
541332038,
68+
541047688,
69+
541087067,
70+
540721665,
71+
540091226,
72+
540607839,
73+
540504076,
74+
540875832,
75+
541166362,
76+
540797133,
77+
540125960,
78+
541346812,
79+
540527811,
80+
540244513,
81+
540008761,
82+
540596191,
83+
540895270,
84+
541064762,
85+
540230274,
86+
540795875,
87+
540227193,
88+
540090262,
89+
540172768,
90+
541145379,
91+
541315376,
92+
541116604,
93+
541156105,
94+
540036470,
95+
541106092,
96+
540735988,
97+
540108945,
98+
540917463,
99+
540685278,
100+
540174281,
101+
540774311,
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
fsid,adaptation
2+
541114211,
3+
540456284,
4+
541229206,
5+
540563324,
6+
541262690,
7+
540651172,
8+
540321926,
9+
541397402,
10+
540835968,
11+
540951325,
12+
540695623,
13+
541245323,
14+
540039428,
15+
540611506,
16+
540451980,
17+
540206660,
18+
541247265,
19+
540793246,
20+
540706732,
21+
540629760,
22+
541008337,
23+
541389052,
24+
540419962,
25+
541268364,
26+
541296035,
27+
541034820,
28+
540151216,
29+
540397030,
30+
541156316,
31+
540886492,
32+
541168970,
33+
541228788,
34+
541082842,
35+
541277095,2687
36+
540635265,
37+
540924465,
38+
540179113,
39+
540368183,
40+
540802128,
41+
540157051,
42+
540599292,
43+
540701698,
44+
541127065,
45+
540381378,
46+
540941201,
47+
540478428,
48+
540608643,
49+
541214101,
50+
541004243,
51+
540805761,
52+
540665287,
53+
541328658,
54+
541335961,
55+
540256544,
56+
540407071,
57+
541312162,
58+
541145330,
59+
540315374,
60+
540788900,
61+
540147226,
62+
540040622,
63+
540768481,
64+
541384755,
65+
540357885,
66+
540515000,6
67+
541332038,
68+
541047688,
69+
541087067,
70+
540721665,
71+
540091226,
72+
540607839,
73+
540504076,
74+
540875832,
75+
541166362,
76+
540797133,
77+
540125960,
78+
541346812,
79+
540527811,
80+
540244513,
81+
540008761,
82+
540596191,
83+
540895270,
84+
541064762,
85+
540230274,
86+
540795875,
87+
540227193,
88+
540090262,
89+
540172768,
90+
541145379,
91+
541315376,
92+
541116604,
93+
541156105,
94+
540036470,
95+
541106092,
96+
540735988,
97+
540108945,
98+
540917463,
99+
540685278,
100+
540174281,
101+
540774311,
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
fsid,adaptation
2+
541114211,
3+
540456284,
4+
541229206,
5+
540563324,
6+
541262690,
7+
540651172,
8+
540321926,
9+
541397402,
10+
540835968,
11+
540951325,
12+
540695623,
13+
541245323,
14+
540039428,
15+
540611506,
16+
540451980,
17+
540206660,
18+
541247265,
19+
540793246,
20+
540706732,
21+
540629760,
22+
541008337,
23+
541389052,
24+
540419962,
25+
541268364,
26+
541296035,
27+
541034820,
28+
540151216,
29+
540397030,
30+
541156316,
31+
540886492,
32+
541168970,
33+
541228788,
34+
541082842,
35+
541277095,2687
36+
540635265,
37+
540924465,
38+
540179113,
39+
540368183,
40+
540802128,
41+
540157051,
42+
540599292,
43+
540701698,
44+
541127065,
45+
540381378,
46+
540941201,
47+
540478428,
48+
540608643,
49+
541214101,
50+
541004243,
51+
540805761,
52+
540665287,
53+
541328658,
54+
541335961,
55+
540256544,
56+
540407071,
57+
541312162,
58+
541145330,
59+
540315374,
60+
540788900,
61+
540147226,
62+
540040622,
63+
540768481,
64+
541384755,
65+
540357885,
66+
540515000,6
67+
541332038,
68+
541047688,
69+
541087067,
70+
540721665,
71+
540091226,
72+
540607839,
73+
540504076,
74+
540875832,
75+
541166362,
76+
540797133,
77+
540125960,
78+
541346812,
79+
540527811,
80+
540244513,
81+
540008761,
82+
540596191,
83+
540895270,
84+
541064762,
85+
540230274,
86+
540795875,
87+
540227193,
88+
540090262,
89+
540172768,
90+
541145379,
91+
541315376,
92+
541116604,
93+
541156105,
94+
540036470,
95+
541106092,
96+
540735988,
97+
540108945,
98+
540917463,
99+
540685278,
100+
540174281,
101+
540774311,

0 commit comments

Comments
 (0)