File tree Expand file tree Collapse file tree 3 files changed +19
-13
lines changed
Expand file tree Collapse file tree 3 files changed +19
-13
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ GET /v2/locations
4545```
4646``` json
4747{
48+ "aggregate" : {
49+ "confirmed" : 272166 ,
50+ "deaths" : 11299 ,
51+ "recovered" : 87256
52+ },
4853 "locations" : [
4954 {
5055 "id" : 0 ,
Original file line number Diff line number Diff line change 33
44@api .route ('/latest' )
55def latest ():
6- # Query parameters.
7- args = request .args
8-
96 # Get the serialized version of all the locations.
107 locations = request .source .get_all ()
11- #print([i.country_code for i in locations])
12-
13- # Filter based on args.
14- if len (args ) > 0 :
15- locations = [i for i in locations for j in args if hasattr (i , j ) and getattr (i , j ) == args [j ]]
168
179 # All the latest information.
1810 # latest = list(map(lambda location: location['latest'], locations))
Original file line number Diff line number Diff line change 55@api .route ('/locations' )
66def locations ():
77 # Query parameters.
8- timelines = strtobool ( request .args . get ( 'timelines' , default = '0' ))
9- country_code = request . args .get ('country_code ' , type = str )
8+ args = request .args
9+ timelines = strtobool ( args .get ('timelines ' , default = '0' ) )
1010
1111 # Retrieve all the locations.
1212 locations = request .source .get_all ()
1313
14- # Filtering my country code if provided.
15- if not country_code is None :
16- locations = list (filter (lambda location : location .country_code == country_code .upper (), locations ))
14+ # Filtering by args if provided.
15+ for i in args :
16+ if i != 'timelines' :
17+ try :
18+ locations = [j for j in locations if getattr (j , i ) == args .get (i , type = str )]
19+ except AttributeError :
20+ print ('TimelinedLocation object does not have attribute {}.' .format (i ))
1721
1822 # Serialize each location and return.
1923 return jsonify ({
24+ 'aggregate' : {
25+ 'confirmed' : sum (map (lambda location : location .confirmed , locations )),
26+ 'deaths' : sum (map (lambda location : location .deaths , locations )),
27+ 'recovered' : sum (map (lambda location : location .recovered , locations )),
28+ },
2029 'locations' : [
2130 location .serialize (timelines ) for location in locations
2231 ]
You can’t perform that action at this time.
0 commit comments