Python strings being scambled when passed to API

69 views Asked by At

The UK Covid Python SDK (https://publichealthengland.github.io/coronavirus-dashboard-api-python-sdk/) can collect data for an area, e.g. Barnsley, using the following code:

data_structure = {...}
region_string = ["areaType=ltla;areaName=Barnsley"]
api = Cov19API(filters=region_string, structure=data_structure)

print(api) returns the following, which works perfectly:

COVID-19 in the UK - API Service
Current parameters: 
{
    "filters": "areaType=ltla;areaName=Barnsley",
    "structure": "{\"date\":\"date\",\"area\":\"areaName\",\"cases\":\"newCasesByPublishDate\"}"
}

I'm trying to call the API for a series of regions within a county using the following code:

for name in Yorkshire['area'].to_list():
    print(name)
    regionString = f'["areaType=ltla;areaName={name}"]'
    print(regionString)
    api = Cov19API(filters=regionString, structure=cases_only)
    print(api)

But for some reason region_string when being passed to Cov19API is coming out scrambled wth semi-colons:

Barnsley
["areaType=ltla;areaName=Barnsley"]
COVID-19 in the UK - API Service
Current parameters: 
{
    "filters": "[;';a;r;e;a;T;y;p;e;=;l;t;l;a;';,; ;';a;r;e;a;N;a;m;e;=;B;a;r;n;s;l;e;y;';]",
    "structure": "{\"date\":\"date\",\"area\":\"areaName\",\"cases\":\"newCasesByPublishDate\"}"
}
...

I presume this is because filter is adding a semi-colon between any blocks with space, but I don't know why it's not accepting the string when the same variable works in the first instance. Any advice would be greatly appreciated.

0

There are 0 answers