Skip to content
Merged
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
Added ability to use filters for aggregate data
  • Loading branch information
SeanCena committed Mar 21, 2020
commit d0fef4f2eb51bab79b15848f8042c1d2dbe99bc1
13 changes: 7 additions & 6 deletions app/routes/v2/latest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from flask import jsonify, request
from flask import request, jsonify
from ...routes import api_v2 as api

@api.route('/latest')
def latest():
#Query parameters.
country_code = request.args.get('country_code', type=str)
# Query parameters.
args = request.args

# Get the serialized version of all the locations.
locations = request.source.get_all()
#print([i.country_code for i in locations])

# Return aggregate data for country if provided.
if not country_code is None:
locations = list(filter(lambda location: location['country_code'] == country_code.upper(), locations))
# Filter based on args.
if len(args) > 0:
locations = [i for i in locations for j in args if hasattr(i, j) and getattr(i, j) == args[j]]

# All the latest information.
# latest = list(map(lambda location: location['latest'], locations))
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.