Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.env
.env
__pycache__/
*.py[cod]
*.log
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.envFile": "${workspaceFolder}/.env",
"python.terminal.useEnvFile": true
}
57 changes: 57 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from flask import Flask, jsonify
from requests.exceptions import RequestException

from services.flight import get_destination_from_flight
from services.news import get_headlines_for_location


app = Flask(__name__)


@app.get("/flight/<flight_number>/news")
def flight_news(flight_number):
try:
destination = get_destination_from_flight(flight_number)
except RequestException:
Comment on lines +13 to +15
return (
jsonify(
{
"success": False,
"stage": "flight",
"reason": "flight_api_unavailable",
}
),
502,
)

if not destination.get("success"):
return jsonify({"success": False, "stage": "flight", **destination}), 404
Comment on lines +27 to +28

try:
headlines = get_headlines_for_location(destination["lat"], destination["lon"])
except RequestException:
Comment on lines +30 to +32
return (
jsonify(
{
"success": False,
"stage": "news",
"reason": "news_api_unavailable",
}
),
502,
)

if not headlines.get("success"):
return jsonify({"success": False, "stage": "news", **headlines}), 502
Comment on lines +44 to +45

return jsonify(
{
"success": True,
"destination": destination,
"articles": headlines["articles"],
}
)


if __name__ == "__main__":
app.run(debug=True)