Skip to content

Commit 5b2d2d0

Browse files
Merge pull request #2278 from IFRCGo/fix/skip-nonworking-ns-endpoints
Skip non-working ns_initiatives endpoints
2 parents 43e1dfe + e85e822 commit 5b2d2d0

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

api/management/commands/ingest_ns_initiatives.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ class Command(BaseCommand):
1919
def handle(self, *args, **kwargs):
2020
logger.info("Starting NS Inititatives")
2121
api_key = settings.NS_INITIATIVES_API_KEY
22-
esf_url = requests.get(f"https://data-api.ifrc.org/api/esf?apikey={api_key}")
23-
nsia_url = requests.get(f"https://data-api.ifrc.org/api/nsia?apikey={api_key}")
24-
cbf_url = requests.get(f"https://data-api.ifrc.org/api/cbf?apikey={api_key}")
22+
urls = [
23+
f"https://data-api.ifrc.org/api/esf?apikey={api_key}",
24+
f"https://data-api.ifrc.org/api/nsia?apikey={api_key}",
25+
f"https://data-api.ifrc.org/api/cbf?apikey={api_key}",
26+
]
2527

26-
# resposne for individual request
27-
esf_response = esf_url.json()
28-
nsia_response = nsia_url.json()
29-
cbf_response = cbf_url.json()
28+
responses = []
29+
for url in urls:
30+
response = requests.get(url)
31+
if response.status_code == 200:
32+
responses.append(response.json())
3033

3134
added = 0
3235

33-
all_fund_data = [esf_response, nsia_response, cbf_response]
34-
flatList = [element for innerList in all_fund_data for element in innerList]
36+
flatList = [element for innerList in responses for element in innerList]
3537
funding_data = pd.DataFrame(
3638
flatList,
3739
columns=[

0 commit comments

Comments
 (0)