Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed 'aggregate' top-level to 'latest'
Also prevented user from filtering by double-underscore functions
  • Loading branch information
SeanCena committed Mar 21, 2020
commit 12813ecfd514cbb2c35d8435bab536cfb4a8131d
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ GET /v2/locations
}
```

Additionally, you can also filter by country ([alpha-2 country_code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
Additionally, you can also filter by any attribute, including province and country ([alpha-2 country_code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
```http
GET /v2/locations?country_code=US
```
Expand Down
4 changes: 2 additions & 2 deletions app/routes/v2/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def locations():

# Filtering by args if provided.
for i in args:
if i != 'timelines':
if i != 'timelines' and i[:2] != '__':
try:
locations = [j for j in locations if getattr(j, i) == args.get(i, type=str)]
except AttributeError:
print('TimelinedLocation object does not have attribute {}.'.format(i))

# Serialize each location and return.
return jsonify({
'aggregate': {
'latest': {
'confirmed': sum(map(lambda location: location.confirmed, locations)),
'deaths' : sum(map(lambda location: location.deaths, locations)),
'recovered': sum(map(lambda location: location.recovered, locations)),
Expand Down