1+ from flask import jsonify
2+ from app import app
3+ from app .data import get_data
4+ from nested_lookup import get_occurrence_of_value
5+ from cachetools import cached , TTLCache
6+
7+
8+ @app .route ('/formatted' )
9+ @cached (cache = TTLCache (maxsize = 1024 , ttl = 900 ))
10+ def full ():
11+ # Get all the categories.
12+ confirmed = get_data ('confirmed' )
13+ deaths = get_data ('deaths' )
14+ recovered = get_data ('recovered' )
15+
16+ # prepare output dictionary
17+ output = []
18+
19+ # Formatting
20+ for locationConfirmed in confirmed ["locations" ]:
21+ deathsData = {}
22+ recoversData = {}
23+
24+ # find matching region for deaths & recovered
25+ targetCoordniates = locationConfirmed ["coordinates" ]
26+
27+ # search for location match: death
28+ for locationDeaths in deaths ["locations" ]:
29+ # check for matching coordinates
30+ if locationDeaths ["coordinates" ] == targetCoordniates :
31+ deathsData = locationDeaths
32+
33+ # search for location match: recovered
34+ for locationRecovers in recovered ["locations" ]:
35+ # check for matching coordinates
36+ if locationRecovers ["coordinates" ] == targetCoordniates :
37+ recoversData = locationRecovers
38+
39+
40+ # add the death statistics to the object
41+ locationOutput = {
42+ 'location' : locationConfirmed ["country" ],
43+ 'coordinates' : targetCoordniates ,
44+ 'confirmed' : locationConfirmed ,
45+ 'deaths' : deathsData ,
46+ 'recovered' : recoversData
47+ }
48+
49+ # add current location to the output
50+ output .append (locationOutput )
51+
52+ return jsonify (output )
0 commit comments