UNICEF Covid Allocations
Anonymous
1,949 views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Oi!
Antes de apertar Run, acesse a tabela via "https://www.unicef.org/supply/covid-19-vaccine-market-dashboard", caso contrário vai dar "não autorizado". Depois é só copiar e colar o "Standard Output" no excel. Melhor conferir os dados. Em pelo menos um (Bahrain), faltou um dado e ou a página da unicef copiou do paÃs acima ou tirou de outro lugar. Para cada situação (variável "R") eu tenho que colocar uma permutação (dicionário "order").
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gzip
import json
import sys
import urllib.request
# https://www.unicef.org/supply/covid-19-vaccine-market-dashboard
response = urllib.request.urlopen('https://wabi-north-europe-api.analysis.windows.net/public/reports/querydata?synchronous=false',
b'{"version":"1.0.0","queries":[{"Query":{"Commands":[{"SemanticQueryDataShapeCommand":{"Query":{"Version":2,"From":[{"Name":"r","Entity":"rpt vw_Dim_WHOCountry","Type":0},{"Name":"r1","Entity":"rpt vw_SCOTracker_Fact_AllocationFromWHO","Type":0},{"Name":"r3","Entity":"rpt VW_SCOTracker_Fact_Delivered_UNICEFPOs","Type":0},{"Name":"r2","Entity":"rpt VW_SCOTracker_FACT_Contracted_UNICEFPOs","Type":0}],"Select":[{"Column":{"Expression":{"SourceRef":{"Source":"r"}},"Property":"WHO Country Name"},"Name":"rpt vw_Dim_WHOCountry.WHO Country Name"},{"Measure":{"Expression":{"SourceRef":{"Source":"r1"}},"Property":"Doses Allocated"},"Name":"rpt vw_SCOTracker_Fact_AllocationFromWHO.Doses Allocated"},{"Measure":{"Expression":{"SourceRef":{"Source":"r3"}},"Property":"Doses Shipped"},"Name":"rpt VW_SCOTracker_Fact_Delivered_UNICEFPOs.Doses Delivered"},{"Measure":{"Expression":{"SourceRef":{"Source":"r2"}},"Property":"Doses Ordered"},"Name":"rpt VW_SCOTracker_FACT_Contracted_UNICEFPOs.Doses Ordered"},{"Measure":{"Expression":{"SourceRef":{"Source":"r2"}},"Property":"Doses ready from supplier"},"Name":"rpt VW_SCOTracker_FACT_Contracted_UNICEFPOs.Doses ready from supplier"},{"Measure":{"Expression":{"SourceRef":{"Source":"r3"}},"Property":"Doses on shipment in transit"},"Name":"rpt VW_SCOTracker_Fact_Delivered_UNICEFPOs.Doses on shipment in progress"}]},"Binding":{"Primary":{"Groupings":[{"Projections":[0,1,2,3,4,5]}]},"DataReduction":{"DataVolume":4,"Primary":{"Top":{}}},"SuppressedJoinPredicates":[1,2,3,4,5],"Version":1}}}]},"QueryId":""}],"cancelQueries":[],"modelId":12516632}')
response_data = json.loads(gzip.decompress(response.read()))
world_data = response_data['results'][0]['result']['data']['dsr']['DS'][0]['PH'][0]['DM0']
order = {
'': [0, 1, 3, 4, 5, 2],
'2': [0, -1, 2, 3, 4, 1],
'6': [0, -1, 1, 2, 3, -1],
'32': [0, 1, 3, 4, -1, 2],
'34': [0, -1, 2, 3, -1, 1],
'40': [0, 1, -1, 2, -1, 3],
'48': [0, 1,3, -1, -1,2],
'52': [0, 1, 2, -1, -1, -1],
'58': [0,-1,-1, -1, -1, 1],
'60': [0, 1, -1, -1, -1, -1],
'62': [0, -1, -1, -1, -1, -1],
}
print('\t'.join(
['Country',
'Allocated',
'Ordered',
'Ready from supplier',
'In transit',
'Shipped']))
fails = []
for country_data in world_data:
R = str(country_data.get('R', ''))
try:
data = []
for idx in order[R]:
if idx == -1:
data.append('0')
else:
data.append(str(country_data['C'][idx]))
print('\t'.join(data))
except:
fails.append(country_data)
if fails:
sys.stderr.write('\nFalhas:\n')
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content