Skip to content

Commit 659b667

Browse files
authored
Merge pull request #2062 from IFRCGo/fix/country-page-bug
Rename env var
2 parents 21de4e0 + df0275f commit 659b667

File tree

7 files changed

+15
-12
lines changed

7 files changed

+15
-12
lines changed

api/management/commands/ingest_gdacs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def handle(self, *args, **options):
6060
"event_type": alert[nspace + "eventtype"],
6161
"alert_level": levels[alert_level],
6262
"alert_score": alert_score,
63-
"severity": alert[nspace + "severity"]["#text"],
63+
"severity": alert[nspace + "severity"].get("#text"),
6464
"severity_unit": alert[nspace + "severity"]["@unit"],
6565
"severity_value": alert[nspace + "severity"]["@value"],
6666
"population_unit": alert[nspace + "population"]["@unit"],

api/management/commands/ingest_ns_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def handle(self, *args, **kwargs):
1717

1818
# Fetch country codes
1919
country_code_url = "https://go-api.ifrc.org/api/NationalSocietiesContacts/"
20-
headers = {'Authorization': f'Basic {settings.NS_DOCUMENT_API_TOKEN}'}
20+
headers = {'Authorization': f'Basic {settings.NS_INITIATIVES_API_TOKEN}'}
2121
country_code_response = requests.get(url=country_code_url, headers=headers)
2222

2323
if country_code_response.status_code != 200:

databank/management/commands/fdrs_annual_income.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ def handle(self, *args, **kwargs):
3333
}
3434
fdrs_data_count += 1
3535
FDRSAnnualIncome.objects.get_or_create(**data)
36-
print(f'create count {fdrs_data_count}')
3736
logger.info(f"Successfully created {fdrs_data_count} country data")

databank/management/commands/ingest_acaps.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime as dt
33
import xmltodict
44
import pandas as pd
5+
import time
56
from dateutil.parser import parse
67

78
from django.core.management.base import BaseCommand
@@ -26,6 +27,7 @@ def handle(self, *args, **kwargs):
2627
"Authorization": "Token %s" % settings.ACAPS_API_TOKEN
2728
}
2829
)
30+
logger.info(f'Importing for country {name}')
2931
response_data = response.json()
3032
if 'results' in response_data and len(response_data['results']):
3133
df = pd.DataFrame.from_records(response_data["results"])
@@ -41,4 +43,5 @@ def handle(self, *args, **kwargs):
4143
'source': df_data[11],
4244
'source_date': df_data[12]
4345
}
44-
AcapsSeasonalCalender.objects.create(**dict_data)
46+
AcapsSeasonalCalender.objects.create(**dict_data)
47+
time.sleep(5)

databank/management/commands/ingest_climate.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def handle(self, *args, **options):
7272
precipitation=precipitation_monthly
7373
)
7474
logger.info('Minimum, maximum and Average temperature of country temperature data added successfully')
75-
print('Minimum, maximum and Average temperature of country temperature data added successfully')
7675

7776
except Exception as ex:
7877
logger.error(f'Error in ingesting climate data: {ex}')
79-
print(f'Error in ingesting climate data: {ex}')
8078
continue

databank/management/commands/ingest_worldbank.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,20 @@ def handle(self, *args, **kwargs):
4040
independent=True
4141
).exclude(iso3="COK"):
4242
country_iso3 = country.iso3
43+
logger.info(f'Importing country {country_iso3}')
4344
for indicator in world_bank_indicators:
4445
page = 1 # Reset the page for each indicator
4546
while True:
46-
response = requests.get(f'https://api.worldbank.org/v2/country/{country_iso3}/indicator/{indicator}?date={daterange}', params={
47+
try:
48+
response = requests.get(f'https://api.worldbank.org/v2/country/{country_iso3}/indicator/{indicator}?date={daterange}', params={
4749
'format': 'json',
4850
'source': 2,
4951
'per_page': 5000 - 1, # World Bank throws error on 5000
5052
'page': page,
51-
})
52-
response.raise_for_status()
53+
})
54+
except requests.exceptions.HTTPError as err:
55+
print(err.response.text)
56+
continue
5357
try:
5458
data_list = response.json()[1]
5559
if data_list is not None and len(data_list) > 0:
@@ -73,7 +77,6 @@ def handle(self, *args, **kwargs):
7377
existing_data = next((data for data in country_dict[geo_id] if data[2] == indicator), None)
7478
if existing_data is None or existing_data[1] < year:
7579
country_dict[geo_id].append((pop, year, indicator))
76-
print(country_dict)
7780
logger.info(json.dumps(country_dict))
7881
if 'pages' in response.json()[0]:
7982
if page >= response.json()[0]['pages']:

main/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
ACAPS_API_TOKEN=(str, None),
104104
NS_DOCUMENT_API_KEY=(str, None),
105105
NS_INITIATIVES_API_KEY=(str, None),
106-
NS_DOCUMENT_API_TOKEN=(str, None)
106+
NS_INITIATIVES_API_TOKEN=(str, None)
107107
)
108108

109109

@@ -525,7 +525,7 @@
525525
ACAPS_API_TOKEN = env('ACAPS_API_TOKEN')
526526
NS_DOCUMENT_API_KEY = env('NS_DOCUMENT_API_KEY')
527527
NS_INITIATIVES_API_KEY = env('NS_INITIATIVES_API_KEY')
528-
NS_DOCUMENT_API_TOKEN = env('NS_DOCUMENT_API_TOKEN')
528+
NS_INITIATIVES_API_TOKEN = env('NS_INITIATIVES_API_TOKEN')
529529

530530
DREF_OP_UPDATE_FINAL_REPORT_UPDATE_ERROR_MESSAGE = "OBSOLETE_PAYLOAD"
531531

0 commit comments

Comments
 (0)