Skip to content

Commit aa607bd

Browse files
committed
Final code for first conversion from flask to quart (no real async yet)
1 parent aedbb01 commit aa607bd

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/10-async-web/acityscape_api/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import flask
1+
import quart
22
from views import city_api
33
from views import home
44
from config import settings
55
import services.weather_service
66
import services.sun_service
77
import services.location_service
88

9-
app = flask.Flask(__name__)
9+
app = quart.Quart(__name__)
1010
is_debug = True
1111

1212
app.register_blueprint(home.blueprint)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Web framework requirements
2-
flask
2+
quart
33

44
# Calling services requirements
55
requests
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import flask
1+
import quart
22
from services import weather_service, sun_service, location_service
33

4-
blueprint = flask.blueprints.Blueprint(__name__, __name__)
4+
blueprint = quart.blueprints.Blueprint(__name__, __name__)
55

66

77
@blueprint.route('/api/weather/<zip_code>/<country>', methods=['GET'])
88
def weather(zip_code: str, country: str):
99
weather_data = weather_service.get_current(zip_code, country)
1010
if not weather_data:
11-
flask.abort(404)
12-
return flask.jsonify(weather_data)
11+
quart.abort(404)
12+
return quart.jsonify(weather_data)
1313

1414

1515
@blueprint.route('/api/sun/<zip_code>/<country>', methods=['GET'])
1616
def sun(zip_code: str, country: str):
1717
lat, long = location_service.get_lat_long(zip_code, country)
1818
sun_data = sun_service.for_today(lat, long)
1919
if not sun_data:
20-
flask.abort(404)
21-
return flask.jsonify(sun_data)
20+
quart.abort(404)
21+
return quart.jsonify(sun_data)

src/10-async-web/acityscape_api/views/home.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import flask
1+
import quart
22

3-
blueprint = flask.blueprints.Blueprint(__name__, __name__)
3+
blueprint = quart.blueprints.Blueprint(__name__, __name__)
44

55

66
@blueprint.route('/')
@@ -12,4 +12,4 @@ def index():
1212

1313
@blueprint.errorhandler(404)
1414
def not_found(_):
15-
return flask.Response("The page was not found.", status=404)
15+
return quart.Response("The page was not found.", status=404)

0 commit comments

Comments
 (0)