Skip to content

Commit

Permalink
Add hdr gii data
Browse files Browse the repository at this point in the history
  • Loading branch information
k9845 committed Jan 22, 2024
1 parent 385fde4 commit c294883
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions databank/management/commands/ingest_hdr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import logging
import requests
from django.core.management.base import BaseCommand
from databank.models import CountryOverview as CO


logger = logging.getLogger(__name__)


class Command(BaseCommand):
help = 'Add HDR GII data'

def handle(self, *args, **kwargs):
for overview in CO.objects.all():
HDR_API = f'https://api.hdrdata.org/CountryIndicators/filter?country={overview.country.iso3}&year=2021&indicator=gii'
hdr_entities = requests.get(HDR_API)
if hdr_entities.status_code != 200:
continue
hdr_entities.raise_for_status()
hdr_entities = hdr_entities.json()
if len(hdr_entities):
hdr_gii = hdr_entities[0]['value']
overview.hdr_gii = hdr_gii
overview.save(update_fields=['hdr_gii'])
18 changes: 18 additions & 0 deletions databank/migrations/0019_countryoverview_hdr_gii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2024-01-22 10:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('databank', '0018_countryoverview_unicef_population_under_18'),
]

operations = [
migrations.AddField(
model_name='countryoverview',
name='hdr_gii',
field=models.FloatField(blank=True, null=True, verbose_name='HDR GII'),
),
]
6 changes: 6 additions & 0 deletions databank/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ class CountryOverview(models.Model):
null=True, blank=True
)

# hdr
hdr_gii = models.FloatField(
verbose_name=_('HDR GII'),
null=True, blank=True
)

class Meta:
verbose_name = _('country overview')
verbose_name_plural = _('countries overview')
Expand Down

0 comments on commit c294883

Please sign in to comment.