-
-
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 #69 from ExpDev07/v2
Version 2 has landed!
- Loading branch information
Showing
19 changed files
with
417 additions
and
110 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
File renamed without changes.
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,20 @@ | ||
class Coordinates: | ||
""" | ||
A position on earth using decimal coordinates (latitude and longitude). | ||
""" | ||
|
||
def __init__(self, latitude, longitude): | ||
self.latitude = latitude | ||
self.longitude = longitude | ||
|
||
def serialize(self): | ||
""" | ||
Serializes the coordinates into a dict. | ||
""" | ||
return { | ||
'latitude' : self.latitude, | ||
'longitude': self.longitude | ||
} | ||
|
||
def __str__(self): | ||
return 'lat: %s, long: %s' % (self.latitude, self.longitude) |
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
from .coordinates import Coordinates | ||
from .utils import countrycodes | ||
|
||
class Location: | ||
""" | ||
A location in the world affected by the coronavirus. | ||
""" | ||
|
||
def __init__(self, id, country, province, coordinates, confirmed, deaths, recovered): | ||
# General info. | ||
self.id = id | ||
self.country = country.strip() | ||
self.province = province.strip() | ||
self.coordinates = coordinates | ||
|
||
# Data. | ||
self.confirmed = confirmed | ||
self.deaths = deaths | ||
self.recovered = recovered | ||
|
||
|
||
@property | ||
def country_code(self): | ||
""" | ||
Gets the alpha-2 code represention of the country. Returns 'XX' if none is found. | ||
""" | ||
return (countrycodes.country_code(self.country) or countrycodes.default_code).upper() | ||
|
||
def serialize(self): | ||
""" | ||
Serializes the location into a dict. | ||
""" | ||
return { | ||
# General info. | ||
'id' : self.id, | ||
'country' : self.country, | ||
'province' : self.province, | ||
'country_code': self.country_code, | ||
|
||
# Coordinates. | ||
'coordinates': self.coordinates.serialize(), | ||
|
||
# Latest data. | ||
'latest': { | ||
'confirmed': self.confirmed.latest, | ||
'deaths' : self.deaths.latest, | ||
'recovered': self.recovered.latest | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,4 +1,5 @@ | ||
from . import confirmed | ||
from . import deaths | ||
from . import recovered | ||
from . import all | ||
# API version 1. | ||
from .v1 import confirmed, deaths, recovered, all | ||
|
||
# API version 2. | ||
from .v2 import locations, latest |
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,7 +1,7 @@ | ||
from flask import jsonify | ||
from flask import current_app as app | ||
from ..data import get_data | ||
from ...services.location.jhu import get_category | ||
|
||
@app.route('/confirmed') | ||
def confirmed(): | ||
return jsonify(get_data('confirmed')) | ||
return jsonify(get_category('confirmed')) |
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,7 +1,7 @@ | ||
from flask import jsonify | ||
from flask import current_app as app | ||
from ..data import get_data | ||
from ...services.location.jhu import get_category | ||
|
||
@app.route('/deaths') | ||
def deaths(): | ||
return jsonify(get_data('deaths')) | ||
return jsonify(get_category('deaths')) |
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,7 +1,7 @@ | ||
from flask import jsonify | ||
from flask import current_app as app | ||
from ..data import get_data | ||
from ...services.location.jhu import get_category | ||
|
||
@app.route('/recovered') | ||
def recovered(): | ||
return jsonify(get_data('recovered')) | ||
return jsonify(get_category('recovered')) |
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,18 @@ | ||
from flask import jsonify, current_app as app | ||
from ...services import jhu | ||
|
||
@app.route('/v2/latest') | ||
def latest(): | ||
# Get the serialized version of all the locations. | ||
locations = [ location.serialize() for location in jhu.get_all() ] | ||
|
||
# All the latest information. | ||
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)), | ||
} | ||
}) |
Oops, something went wrong.