From 1537d4be4a39ef70f189825c02a444e20be38aaa Mon Sep 17 00:00:00 2001 From: KarandeepSingh258255 Date: Thu, 9 Jul 2026 04:50:21 -0400 Subject: [PATCH] app working --- .gitignore | 5 +++- .vscode/settings.json | 4 +++ app.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 2eea525..f86ec77 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.env \ No newline at end of file +.env +__pycache__/ +*.py[cod] +*.log diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7012593 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.envFile": "${workspaceFolder}/.env", + "python.terminal.useEnvFile": true +} diff --git a/app.py b/app.py index e69de29..6d65f39 100644 --- a/app.py +++ b/app.py @@ -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//news") +def flight_news(flight_number): + try: + destination = get_destination_from_flight(flight_number) + except RequestException: + return ( + jsonify( + { + "success": False, + "stage": "flight", + "reason": "flight_api_unavailable", + } + ), + 502, + ) + + if not destination.get("success"): + return jsonify({"success": False, "stage": "flight", **destination}), 404 + + try: + headlines = get_headlines_for_location(destination["lat"], destination["lon"]) + except RequestException: + return ( + jsonify( + { + "success": False, + "stage": "news", + "reason": "news_api_unavailable", + } + ), + 502, + ) + + if not headlines.get("success"): + return jsonify({"success": False, "stage": "news", **headlines}), 502 + + return jsonify( + { + "success": True, + "destination": destination, + "articles": headlines["articles"], + } + ) + + +if __name__ == "__main__": + app.run(debug=True)