Skip to content

Commit 002e1af

Browse files
author
ExpDev07
committed
History now returns a string-int pair and not string-string + some Cleanup
1 parent f22bd25 commit 002e1af

File tree

10 files changed

+61
-51
lines changed

10 files changed

+61
-51
lines changed

Pipfile.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/__init__.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
from flask import Flask
2-
from flask import json
32
from flask_cors import CORS
4-
from app.settings import *
3+
from . import settings
54

6-
# Create the flask application.
7-
app = Flask(__name__)
8-
CORS(app)
5+
def create_app():
6+
"""
7+
Construct the core application.
8+
"""
99

10-
# Import assets, models, routes, etc.
11-
from . import routes
10+
# Create flask app with CORS enabled.
11+
app = Flask(__name__)
12+
CORS(app)
1213

13-
# Run the application (server).
14-
if __name__ == 'main':
15-
app.run(port=PORT, threaded=True)
14+
# Set app config from settings.
15+
app.config.from_pyfile('settings.py');
16+
17+
with app.app_context():
18+
# Import routes.
19+
from . import routes
20+
21+
# Return created app.
22+
return app

app/data/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import csv
33
from datetime import datetime
44
from cachetools import cached, TTLCache
5-
from app.utils import countrycodes, date as date_util
5+
from ..utils import countrycodes, date as date_util
66

77
"""
88
Base URL for fetching data.
@@ -30,7 +30,10 @@ def get_data(category):
3030

3131
for item in data:
3232
# Filter out all the dates.
33-
history = dict(filter(lambda element: date_util.is_date(element[0]), item.items()))
33+
dates = dict(filter(lambda element: date_util.is_date(element[0]), item.items()))
34+
35+
# Make location history from dates.
36+
history = { date: int(amount or 0) for date, amount in dates.items() };
3437

3538
# Country for this location.
3639
country = item['Country/Region']

app/models/location.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Location():
2+
"""
3+
A location in the world affected by the coronavirus.
4+
"""

app/routes/all.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from flask import jsonify
2-
from app import app
3-
from app.data import get_data
2+
from flask import current_app as app
3+
from ..data import get_data
44

55
@app.route('/all')
66
def all():

app/routes/confirmed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from flask import jsonify
2-
from app import app
3-
from app.data import get_data
2+
from flask import current_app as app
3+
from ..data import get_data
44

55
@app.route('/confirmed')
66
def confirmed():

app/routes/deaths.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from flask import jsonify
2-
from app import app
3-
from app.data import get_data
2+
from flask import current_app as app
3+
from ..data import get_data
44

55
@app.route('/deaths')
66
def deaths():

app/routes/recovered.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from flask import jsonify
2-
from app import app
3-
from app.data import get_data
2+
from flask import current_app as app
3+
from ..data import get_data
44

55
@app.route('/recovered')
66
def recovered():

app/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
"""
88
The port to serve the app application on.
99
"""
10-
PORT = int(os.getenv('port', 5000))
10+
PORT = int(os.getenv('PORT', 5000))

app/utils/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)