I am trying to retrieve data from the API using the metrics renaming feature. The structure I am providing to the API is slightly nested. Is this not support as data in the response is missing.
from uk_covid19 import Cov19API
import pprint
structure = {
"date": "date",
"name": "areaName",
"code": "areaCode",
"stats": {
"cases": {
"Daily cases": "newCasesByPublishDate",
"Cumulative cases": "cumCasesByPublishDate",
"Male cases": "maleCases",
"Female cases": "femaleCases",
"Hospital cases": "hospitalCases",
"COVID-19 occupied beds with mechanical ventilators": "covidOccupiedMVBeds"
},
"deaths": {
"Daily deaths": "newDeaths28DaysByDeathDate",
"Cumulative deaths": "cumDeaths28DaysByDeathDate"
},
"admissions": {
"New admissions": "newAdmissions",
"Cumulative admissions": "cumAdmissions"
},
"tests": {
"New pillar one tests by publish date": {
"metadata": "Pillar 1 (NHS and, in England, PHE)",
"value": "newPillarOneTestsByPublishDate"
},
"Cumulative pillar one tests by publish date": {
"metadata": "Pillar 1 (NHS and, in England, PHE)",
"value": "cumPillarOneTestsByPublishDate"
},
"New pillar two tests by publish date": {
"metadata": "Pillar 2 (Commercial partners)",
"value": "newPillarTwoTestsByPublishDate"
},
"Cumulative pillar two tests by publish date": {
"metadata": "Pillar 2 (Commercial partners)",
"value": "cumPillarTwoTestsByPublishDate"
},
"New pillar three tests by publish date": {
"metadata": "Pillar 3 (Antibody)",
"value": "newPillarThreeTestsByPublishDate"
},
"Cumulative pillar three tests by publish date": {
"metadata": "Pillar 3 (Antibody)",
"value": "cumPillarThreeTestsByPublishDate"
},
"New pillar four tests by publish date": {
"metadata": "Pillar 4 (Surveillance)",
"value": "newPillarFourTestsByPublishDate"
},
"Cumulative pillar four tests by publish date": {
"metadata": "Pillar 4 (Surveillance)",
"value": "cumPillarFourTestsByPublishDate"
}
}
}
}
# Instantiate API object
api = Cov19API(
filters=["areaType=nation"],
structure=structure,
latest_by="newCasesByPublishDate"
)
# Obtain JSON from the API
response = api.get_json()
pprint.pprint(response)
return response
Below is the response I receive. admissions
and cases
and deaths
all have no data returned. However, tests
which is heavily nested does return data 🤔
{'data': [{'code': 'E92000001',
'date': '2020-09-18',
'name': 'England',
'stats': {'admissions': {'Cumulative admissions': 'cumAdmissions',
'New admissions': 'newAdmissions'},
'cases': {'COVID-19 occupied beds with mechanical ventilators': 'covidOccupiedMVBeds',
'Cumulative cases': 'cumCasesByPublishDate',
'Daily cases': 'newCasesByPublishDate',
'Female cases': 'femaleCases',
'Hospital cases': 'hospitalCases',
'Male cases': 'maleCases'},
'deaths': {'Cumulative deaths': 'cumDeaths28DaysByDeathDate',
'Daily deaths': 'newDeaths28DaysByDeathDate'},
'tests': {'Cumulative pillar four tests by publish date': {'metadata': 'Pillar '
'4 '
'(Surveillance)',
'value': None},
'Cumulative pillar one tests by publish date': {'metadata': 'Pillar '
'1 '
'(NHS '
'and, '
'in '
'England, '
'PHE)',
'value': 5826554},
'Cumulative pillar three tests by publish date': {'metadata': 'Pillar '
'3 '
'(Antibody)',
'value': 1628603},
'Cumulative pillar two tests by publish date': {'metadata': 'Pillar '
'2 '
'(Commercial '
'partners)',
'value': 9580578},
'New pillar four tests by publish date': {'metadata': 'Pillar '
'4 '
'(Surveillance)',
'value': None},
'New pillar one tests by publish date': {'metadata': 'Pillar '
'1 '
'(NHS '
'and, '
'in '
'England, '
'PHE)',
'value': 64639},
'New pillar three tests by publish date': {'metadata': 'Pillar '
'3 '
'(Antibody)',
'value': 6647},
'New pillar two tests by publish date': {'metadata': 'Pillar '
'2 '
'(Commercial '
'partners)',
'value': 133978}}}},
{'code': 'N92000002',
'date': '2020-09-18',
'name': 'Northern Ireland',
'stats': {'admissions': {'Cumulative admissions': 'cumAdmissions',
'New admissions': 'newAdmissions'},
'cases': {'COVID-19 occupied beds with mechanical ventilators': 'covidOccupiedMVBeds',
'Cumulative cases': 'cumCasesByPublishDate',
'Daily cases': 'newCasesByPublishDate',
'Female cases': 'femaleCases',
'Hospital cases': 'hospitalCases',
'Male cases': 'maleCases'},
'deaths': {'Cumulative deaths': 'cumDeaths28DaysByDeathDate',
'Daily deaths': 'newDeaths28DaysByDeathDate'},
'tests': {'Cumulative pillar four tests by publish date': {'metadata': 'Pillar '
'4 '
'(Surveillance)',
'value': None},
'Cumulative pillar one tests by publish date': {'metadata': 'Pillar '
'1 '
'(NHS '
'and, '
'in '
'England, '
'PHE)',
'value': 196035},
'Cumulative pillar three tests by publish date': {'metadata': 'Pillar '
'3 '
'(Antibody)',
'value': None},
'Cumulative pillar two tests by publish date': {'metadata': 'Pillar '
'2 '
'(Commercial '
'partners)',
'value': 222131},
'New pillar four tests by publish date': {'metadata': 'Pillar '
'4 '
'(Surveillance)',
'value': None},
'New pillar one tests by publish date': {'metadata': 'Pillar '
'1 '
'(NHS '
'and, '
'in '
'England, '
'PHE)',
'value': 1897},
'New pillar three tests by publish date': {'metadata': 'Pillar '
'3 '
'(Antibody)',
'value': None},
'New pillar two tests by publish date': {'metadata': 'Pillar '
'2 '
'(Commercial '
'partners)',
'value': 4612}}}},
{'code': 'S92000003',
'date': '2020-09-18',
'name': 'Scotland',
'stats': {'admissions': {'Cumulative admissions': 'cumAdmissions',
'New admissions': 'newAdmissions'},
'cases': {'COVID-19 occupied beds with mechanical ventilators': 'covidOccupiedMVBeds',
'Cumulative cases': 'cumCasesByPublishDate',
'Daily cases': 'newCasesByPublishDate',
'Female cases': 'femaleCases',
'Hospital cases': 'hospitalCases',
'Male cases': 'maleCases'},
'deaths': {'Cumulative deaths': 'cumDeaths28DaysByDeathDate',
'Daily deaths': 'newDeaths28DaysByDeathDate'},
'tests': {'Cumulative pillar four tests by publish date': {'metadata': 'Pillar '
'4 '
'(Surveillance)',
'value': None},
'Cumulative pillar one tests by publish date': {'metadata': 'Pillar '
'1 '
'(NHS '
'and, '
'in '
'England, '
'PHE)',
'value': 616532},
'Cumulative pillar three tests by publish date': {'metadata': 'Pillar '
'3 '
'(Antibody)',
'value': None},
'Cumulative pillar two tests by publish date': {'metadata': 'Pillar '
'2 '
'(Commercial '
'partners)',
'value': 850063},
'New pillar four tests by publish date': {'metadata': 'Pillar '
'4 '
'(Surveillance)',
'value': None},
'New pillar one tests by publish date': {'metadata': 'Pillar '
'1 '
'(NHS '
'and, '
'in '
'England, '
'PHE)',
'value': 6015},
'New pillar three tests by publish date': {'metadata': 'Pillar '
'3 '
'(Antibody)',
'value': None},
'New pillar two tests by publish date': {'metadata': 'Pillar '
'2 '
'(Commercial '
'partners)',
'value': 11274}}}},
{'code': 'W92000004',
'date': '2020-09-18',
'name': 'Wales',
'stats': {'admissions': {'Cumulative admissions': 'cumAdmissions',
'New admissions': 'newAdmissions'},
'cases': {'COVID-19 occupied beds with mechanical ventilators': 'covidOccupiedMVBeds',
'Cumulative cases': 'cumCasesByPublishDate',
'Daily cases': 'newCasesByPublishDate',
'Female cases': 'femaleCases',
'Hospital cases': 'hospitalCases',
'Male cases': 'maleCases'},
'deaths': {'Cumulative deaths': 'cumDeaths28DaysByDeathDate',
'Daily deaths': 'newDeaths28DaysByDeathDate'},
'tests': {'Cumulative pillar four tests by publish date': {'metadata': 'Pillar '
'4 '
'(Surveillance)',
'value': None},
'Cumulative pillar one tests by publish date': {'metadata': 'Pillar '
'1 '
'(NHS '
'and, '
'in '
'England, '
'PHE)',
'value': 377348},
'Cumulative pillar three tests by publish date': {'metadata': 'Pillar '
'3 '
'(Antibody)',
'value': None},
'Cumulative pillar two tests by publish date': {'metadata': 'Pillar '
'2 '
'(Commercial '
'partners)',
'value': 326229},
'New pillar four tests by publish date': {'metadata': 'Pillar '
'4 '
'(Surveillance)',
'value': None},
'New pillar one tests by publish date': {'metadata': 'Pillar '
'1 '
'(NHS '
'and, '
'in '
'England, '
'PHE)',
'value': 3396},
'New pillar three tests by publish date': {'metadata': 'Pillar '
'3 '
'(Antibody)',
'value': None},
'New pillar two tests by publish date': {'metadata': 'Pillar '
'2 '
'(Commercial '
'partners)',
'value': 7388}}}}],
'lastUpdate': '2020-09-18T14:04:49.000000Z',
'length': 4,
'totalPages': 1}
Any help is much appreciated.