-
-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from ExpDev07/multiple-sources
Basis for providing multiple data-sources.
- Loading branch information
Showing
10 changed files
with
125 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from ..services.location.jhu import JhuLocationService | ||
|
||
# Mapping of services to data-sources. | ||
data_sources = { | ||
'jhu': JhuLocationService(), | ||
} | ||
|
||
def data_source(source): | ||
""" | ||
Retrieves the provided data-source service. | ||
:returns: The service. | ||
:rtype: LocationService | ||
""" | ||
return data_sources.get(source.lower()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
from flask import jsonify | ||
from flask import request, jsonify | ||
from ...routes import api_v2 as api | ||
from ...services import jhu | ||
|
||
@api.route('/latest') | ||
def latest(): | ||
# Get the serialized version of all the locations. | ||
locations = [ location.serialize() for location in jhu.get_all() ] | ||
locations = request.source.get_all() | ||
|
||
# All the latest information. | ||
latest = list(map(lambda location: location['latest'], locations)) | ||
# latest = list(map(lambda location: location['latest'], locations)) | ||
|
||
return jsonify({ | ||
'latest': { | ||
'confirmed': sum(map(lambda latest: latest['confirmed'], latest)), | ||
'deaths' : sum(map(lambda latest: latest['deaths'], latest)), | ||
'recovered': sum(map(lambda latest: latest['recovered'], 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)), | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters