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

Commit 9bc98bb

Browse files
committed
Push up the connection limit to param
1 parent a469917 commit 9bc98bb

File tree

8 files changed

+45
-30
lines changed

8 files changed

+45
-30
lines changed

firststreet/api/adaptation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,36 @@ class Adaptation(Api):
1616
get_summary: Retrieves a list of Adaptation Summary for the given list of IDs
1717
"""
1818

19-
def get_detail(self, fsids, csv=False):
19+
def get_detail(self, fsids, csv=False, limit=100):
2020
"""Retrieves adaptation detail product data from the First Street Foundation API given a list of FSIDs and
2121
returns a list of Adaptation Detail objects.
2222
2323
Args:
2424
fsids (list): A First Street ID
2525
csv (bool): To output extracted data to a csv or not
26+
limit (int): max number of connections to make
2627
Returns:
2728
A list of Adaptation Detail
2829
"""
2930

3031
# Get data from api and create objects
31-
api_datas = self.call_api(fsids, "adaptation", "detail", None)
32+
api_datas = self.call_api(fsids, "adaptation", "detail", None, limit=limit)
3233
product = [AdaptationDetail(api_data) for api_data in api_datas]
3334

3435
if csv:
3536
csv_format.to_csv(product, "adaptation", "detail")
3637

3738
return product
3839

39-
def get_summary(self, fsids, location_type, csv=False):
40+
def get_summary(self, fsids, location_type, csv=False, limit=100):
4041
"""Retrieves adaptation summary product data from the First Street Foundation API given a list of FSIDs and
4142
returns a list of Adaptation Summary objects.
4243
4344
Args:
4445
fsids (list): A First Street ID
4546
location_type (str): The location lookup type
4647
csv (bool): To output extracted data to a csv or not
48+
limit (int): max number of connections to make
4749
Returns:
4850
A list of Adaptation Summary
4951
"""
@@ -54,7 +56,7 @@ def get_summary(self, fsids, location_type, csv=False):
5456
raise TypeError("location is not a string")
5557

5658
# Get data from api and create objects
57-
api_datas = self.call_api(fsids, "adaptation", "summary", location_type)
59+
api_datas = self.call_api(fsids, "adaptation", "summary", location_type, limit=limit)
5860
product = [AdaptationSummary(api_data) for api_data in api_datas]
5961

6062
if csv:

firststreet/api/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Api:
2020
def __init__(self, http):
2121
self._http = http
2222

23-
def call_api(self, fsids, product, product_subtype, location):
23+
def call_api(self, fsids, product, product_subtype, location, limit=100):
2424
"""Receives FSIDs, a product, a product subtype, and a location to create and call an endpoint to the First
2525
Street Foundation API.
2626
@@ -29,6 +29,7 @@ def call_api(self, fsids, product, product_subtype, location):
2929
product (str): The overall product to call
3030
product_subtype (str): The product subtype (if suitable)
3131
location (str/None): The location lookup type (if suitable)
32+
limit (int): max number of connections to make
3233
Returns:
3334
A list of JSON responses
3435
"""
@@ -51,6 +52,6 @@ def call_api(self, fsids, product, product_subtype, location):
5152

5253
# Asynchronously call the API for each endpoint
5354
loop = asyncio.get_event_loop()
54-
response = loop.run_until_complete(self._http.endpoint_execute(endpoints))
55+
response = loop.run_until_complete(self._http.endpoint_execute(endpoints, limit))
5556

5657
return response

firststreet/api/environmental.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ class Environmental(Api):
1414
get_precipitation: Retrieves a list of Environmental Precipitation for the given list of IDs
1515
"""
1616

17-
def get_precipitation(self, fsids, csv=False):
17+
def get_precipitation(self, fsids, csv=False, limit=100):
1818
"""Retrieves environmental precipitation product data from the First Street Foundation API given a list of FSIDs
1919
and returns a list of Environmental Precipitation objects.
2020
2121
Args:
2222
fsids (list): A First Street ID
2323
csv (bool): To output extracted data to a csv or not
24+
limit (int): max number of connections to make
2425
Returns:
2526
A list of Adaptation Detail
2627
"""
2728

2829
# Get data from api and create objects
29-
api_datas = self.call_api(fsids, "environmental", "precipitation", "county")
30+
api_datas = self.call_api(fsids, "environmental", "precipitation", "county", limit=limit)
3031
product = [EnvironmentalPrecipitation(api_data) for api_data in api_datas]
3132

3233
if csv:

firststreet/api/fema.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ class Fema(Api):
1515
get_nfip: Retrieves a list of Fema Nfip for the given list of IDs
1616
"""
1717

18-
def get_nfip(self, fsids, location_type, csv=False):
18+
def get_nfip(self, fsids, location_type, csv=False, limit=100):
1919
"""Retrieves fema nfip product data from the First Street Foundation API given a list of FSIDs and
2020
returns a list of Fema Nfip objects.
2121
2222
Args:
2323
fsids (list): A First Street ID
2424
location_type (str): The location lookup type
2525
csv (bool): To output extracted data to a csv or not
26+
limit (int): max number of connections to make
2627
Returns:
2728
A list of Fema Nfip
2829
Raises:
@@ -36,7 +37,7 @@ def get_nfip(self, fsids, location_type, csv=False):
3637
raise TypeError("location is not a string")
3738

3839
# Get data from api and create objects
39-
api_datas = self.call_api(fsids, "fema", "nfip", location_type)
40+
api_datas = self.call_api(fsids, "fema", "nfip", location_type, limit=limit)
4041
product = [FemaNfip(api_data) for api_data in api_datas]
4142

4243
if csv:

firststreet/api/historic.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,36 @@ class Historic(Api):
1616
get_summary: Retrieves a list of Historic Summary for the given list of IDs
1717
"""
1818

19-
def get_event(self, fsids, csv=False):
19+
def get_event(self, fsids, csv=False, limit=100):
2020
"""Retrieves historic event product data from the First Street Foundation API given a list of FSIDs and
2121
returns a list of Historic Event objects.
2222
2323
Args:
2424
fsids (list): A First Street ID
2525
csv (bool): To output extracted data to a csv or not
26+
limit (int): max number of connections to make
2627
Returns:
2728
A list of Historic Event
2829
"""
2930

3031
# Get data from api and create objects
31-
api_datas = self.call_api(fsids, "historic", "event", None)
32+
api_datas = self.call_api(fsids, "historic", "event", None, limit)
3233
product = [HistoricEvent(api_data) for api_data in api_datas]
3334

3435
if csv:
3536
csv_format.to_csv(product, "historic", "event")
3637

3738
return product
3839

39-
def get_summary(self, fsids, location_type, csv=False):
40+
def get_summary(self, fsids, location_type, csv=False, limit=100):
4041
"""Retrieves historic summary product data from the First Street Foundation API given a list of FSIDs and
4142
returns a list of Historic Summary objects.
4243
4344
Args:
4445
fsids (list): A First Street ID
4546
location_type (str): The location lookup type
4647
csv (bool): To output extracted data to a csv or not
48+
limit (int): max number of connections to make
4749
Returns:
4850
A list of Historic Summary
4951
"""
@@ -54,7 +56,7 @@ def get_summary(self, fsids, location_type, csv=False):
5456
raise TypeError("location is not a string")
5557

5658
# Get data from api and create objects
57-
api_datas = self.call_api(fsids, "historic", "summary", location_type)
59+
api_datas = self.call_api(fsids, "historic", "summary", location_type, limit)
5860
product = [HistoricSummary(api_data) for api_data in api_datas]
5961

6062
if csv:

firststreet/api/location.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ class Location(Api):
1818
get_summary: Retrieves a list of Location Summary for the given list of IDs
1919
"""
2020

21-
def get_detail(self, fsids, location_type, csv=False):
21+
def get_detail(self, fsids, location_type, csv=False, limit=100):
2222
"""Retrieves location detail product data from the First Street Foundation API given a list of FSIDs and
2323
returns a list of Location Detail objects.
2424
2525
Args:
2626
fsids (list): A First Street ID
2727
location_type (str): The location lookup type
2828
csv (bool): To output extracted data to a csv or not
29+
limit (int): max number of connections to make
2930
Returns:
3031
A list of Location Detail
3132
Raises:
@@ -39,7 +40,7 @@ def get_detail(self, fsids, location_type, csv=False):
3940
raise TypeError("location is not a string")
4041

4142
# Get data from api and create objects
42-
api_datas = self.call_api(fsids, "location", "detail", location_type)
43+
api_datas = self.call_api(fsids, "location", "detail", location_type, limit=limit)
4344

4445
if location_type == 'property':
4546
product = [LocationDetailProperty(api_data) for api_data in api_datas]
@@ -73,14 +74,15 @@ def get_detail(self, fsids, location_type, csv=False):
7374

7475
return product
7576

76-
def get_summary(self, fsids, location_type, csv=False):
77+
def get_summary(self, fsids, location_type, csv=False, limit=100):
7778
"""Retrieves location summary product data from the First Street Foundation API given a list of FSIDs and
7879
returns a list of Location Summary objects.
7980
8081
Args:
8182
fsids (list): A First Street ID
8283
location_type (str): The location lookup type
8384
csv (bool): To output extracted data to a csv or not
85+
limit (int): max number of connections to make
8486
Returns:
8587
A list of Location Summary
8688
Raises:
@@ -94,7 +96,7 @@ def get_summary(self, fsids, location_type, csv=False):
9496
raise TypeError("location is not a string")
9597

9698
# Get data from api and create objects
97-
api_datas = self.call_api(fsids, "location", "summary", location_type)
99+
api_datas = self.call_api(fsids, "location", "summary", location_type, limit=limit)
98100

99101
if location_type == "property":
100102
product = [LocationSummaryProperty(api_data) for api_data in api_datas]

firststreet/api/probability.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,57 @@ class Probability(Api):
2020
get_cumulative: Retrieves a list of Probability Depth for the given list of IDs
2121
"""
2222

23-
def get_depth(self, fsids, csv=False):
23+
def get_depth(self, fsids, csv=False, limit=100):
2424
"""Retrieves probability depth product data from the First Street Foundation API given a list of FSIDs and
2525
returns a list of Probability Depth objects.
2626
2727
Args:
2828
fsids (list): A First Street ID
2929
csv (bool): To output extracted data to a csv or not
30+
limit (int): max number of connections to make
3031
Returns:
3132
A list of Probability Depth
3233
"""
3334

3435
# Get data from api and create objects
35-
api_datas = self.call_api(fsids, "probability", "depth", "property")
36+
api_datas = self.call_api(fsids, "probability", "depth", "property", limit=limit)
3637
product = [ProbabilityDepth(api_data) for api_data in api_datas]
3738

3839
if csv:
3940
csv_format.to_csv(product, "probability", "depth")
4041

4142
return product
4243

43-
def get_chance(self, fsids, csv=False):
44+
def get_chance(self, fsids, csv=False, limit=100):
4445
"""Retrieves probability chance product data from the First Street Foundation API given a list of FSIDs and
4546
returns a list of Probability Chance objects.
4647
4748
Args:
4849
fsids (list): A First Street ID
4950
csv (bool): To output extracted data to a csv or not
51+
limit (int): max number of connections to make
5052
Returns:
5153
A list of Probability Chance
5254
"""
5355

5456
# Get data from api and create objects
55-
api_datas = self.call_api(fsids, "probability", "chance", "property")
57+
api_datas = self.call_api(fsids, "probability", "chance", "property", limit=limit)
5658
product = [ProbabilityChance(api_data) for api_data in api_datas]
5759

5860
if csv:
5961
csv_format.to_csv(product, "probability", "chance")
6062

6163
return product
6264

63-
def get_count(self, fsids, location_type, csv=False):
65+
def get_count(self, fsids, location_type, csv=False, limit=100):
6466
"""Retrieves probability count product data from the First Street Foundation API given a list of FSIDs and
6567
returns a list of Probability Count objects.
6668
6769
Args:
6870
fsids (list): A First Street ID
6971
location_type (str): The location lookup type
7072
csv (bool): To output extracted data to a csv or not
73+
limit (int): max number of connections to make
7174
Returns:
7275
A list of Probability Count
7376
Raises:
@@ -81,47 +84,49 @@ def get_count(self, fsids, location_type, csv=False):
8184
raise TypeError("location is not a string")
8285

8386
# Get data from api and create objects
84-
api_datas = self.call_api(fsids, "probability", "count", location_type)
87+
api_datas = self.call_api(fsids, "probability", "count", location_type, limit=limit)
8588
product = [ProbabilityCount(api_data) for api_data in api_datas]
8689

8790
if csv:
8891
csv_format.to_csv(product, "probability", "count", location_type)
8992

9093
return product
9194

92-
def get_count_summary(self, fsids, csv=False):
95+
def get_count_summary(self, fsids, csv=False, limit=100):
9396
"""Retrieves probability Count-Summary product data from the First Street Foundation API given a list of FSIDs
9497
and returns a list of Probability Count-Summary object.
9598
9699
Args:
97100
fsids (list): A First Street ID
98101
csv (bool): To output extracted data to a csv or not
102+
limit (int): max number of connections to make
99103
Returns:
100104
A list of Probability Count-Summary
101105
"""
102106

103107
# Get data from api and create objects
104-
api_datas = self.call_api(fsids, "probability", "count-summary", "property")
108+
api_datas = self.call_api(fsids, "probability", "count-summary", "property", limit)
105109
product = [ProbabilityCountSummary(api_data) for api_data in api_datas]
106110

107111
if csv:
108112
csv_format.to_csv(product, "probability", "count-summary")
109113

110114
return product
111115

112-
def get_cumulative(self, fsids, csv=False):
116+
def get_cumulative(self, fsids, csv=False, limit=100):
113117
"""Retrieves probability cumulative product data from the First Street Foundation API given a list of FSIDs and
114118
returns a list of Probability Cumulative object.
115119
116120
Args:
117121
fsids (list): A First Street ID
118122
csv (bool): To output extracted data to a csv or not
123+
limit (int): max number of connections to make
119124
Returns:
120125
A list of Probability Cumulative
121126
"""
122127

123128
# Get data from api and create objects
124-
api_datas = self.call_api(fsids, "probability", "cumulative", "property")
129+
api_datas = self.call_api(fsids, "probability", "cumulative", "property", limit=limit)
125130
product = [ProbabilityCumulative(api_data) for api_data in api_datas]
126131

127132
if csv:

firststreet/http_util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ def __init__(self, api_key, options=None):
4040
}}
4141
self.version = SUMMARY_VERSION
4242

43-
async def endpoint_execute(self, endpoints):
43+
async def endpoint_execute(self, endpoints, limit=100):
4444
"""Asynchronously calls each endpoint and returns the JSON responses
4545
Args:
4646
endpoints (list): List of endpoints to get
47+
limit (int): max number of connections to make
4748
Returns:
4849
The list of JSON responses corresponding to each endpoint
4950
"""
5051

51-
connector = aiohttp.TCPConnector()
52+
connector = aiohttp.TCPConnector(limit_per_host=limit)
5253
session = aiohttp.ClientSession(connector=connector)
5354

5455
try:

0 commit comments

Comments
 (0)