From de5078f741c1e0f588313d525bae53129c224654 Mon Sep 17 00:00:00 2001 From: MJ Rossetti Date: Tue, 18 Apr 2023 11:38:04 -0400 Subject: [PATCH 1/5] Render HTML pages --- web_app/routes/home_routes.py | 12 ++++++------ web_app/templates/about.html | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/web_app/routes/home_routes.py b/web_app/routes/home_routes.py index 1f1bc85..45bf3f0 100644 --- a/web_app/routes/home_routes.py +++ b/web_app/routes/home_routes.py @@ -7,14 +7,14 @@ @home_routes.route("/home") def index(): print("HOME...") - return "Welcome Home" - #return render_template("home.html") + #return "Welcome Home" + return render_template("home.html") @home_routes.route("/about") def about(): print("ABOUT...") - return "About Me" - #return render_template("about.html") + #return "About Me" + return render_template("about.html") @home_routes.route("/hello") def hello_world(): @@ -27,5 +27,5 @@ def hello_world(): name = url_params.get("name") or "World" message = f"Hello, {name}!" - return message - #return render_template("hello.html", message=message) + #return message + return render_template("hello.html", message=message) diff --git a/web_app/templates/about.html b/web_app/templates/about.html index 11143b4..0211a20 100644 --- a/web_app/templates/about.html +++ b/web_app/templates/about.html @@ -2,7 +2,7 @@ {% block content %} -

About Me<

+

About Me

This is the about page

From f8c83dea65e89526879d0b84cb089e589dfe7725 Mon Sep 17 00:00:00 2001 From: MJ Rossetti Date: Tue, 18 Apr 2023 11:53:46 -0400 Subject: [PATCH 2/5] Use Bootstrap Layout --- web_app/templates/about.html | 3 +- web_app/templates/bootstrap_5_layout.html | 96 +++++++++++++++++++++++ web_app/templates/hello.html | 4 +- web_app/templates/home.html | 4 +- web_app/templates/stocks_dashboard.html | 3 +- web_app/templates/stocks_form.html | 5 +- 6 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 web_app/templates/bootstrap_5_layout.html diff --git a/web_app/templates/about.html b/web_app/templates/about.html index 0211a20..0b8773a 100644 --- a/web_app/templates/about.html +++ b/web_app/templates/about.html @@ -1,4 +1,5 @@ -{% extends "layout.html" %} +{% extends "bootstrap_5_layout.html" %} +{% set active_page = "about" %} {% block content %} diff --git a/web_app/templates/bootstrap_5_layout.html b/web_app/templates/bootstrap_5_layout.html new file mode 100644 index 0000000..756200b --- /dev/null +++ b/web_app/templates/bootstrap_5_layout.html @@ -0,0 +1,96 @@ + + + + + + + + + + Hello, world! + + + + + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} + + + {% endfor %} + {% endif %} + {% endwith %} + + + {% set nav_links = [ + ('/about', 'about', 'About'), + ('/hello', 'hello', 'Hello'), + ('/stocks/form', 'stocks_form', 'Stocks Form') + ] -%} + {% set active_page = active_page|default('home') -%} + + +
+ + +
+ {% block content %} + {% endblock %} +
+ +
+
+ © Copyright 2023 [Your Name Here] | + Source +
+
+ + + + + + diff --git a/web_app/templates/hello.html b/web_app/templates/hello.html index bb6d064..bd60482 100644 --- a/web_app/templates/hello.html +++ b/web_app/templates/hello.html @@ -1,4 +1,6 @@ -{% extends "layout.html" %} +{% extends "bootstrap_5_layout.html" %} +{% set active_page = "hello" %} + {% block content %} diff --git a/web_app/templates/home.html b/web_app/templates/home.html index bd37f85..63a2a5f 100644 --- a/web_app/templates/home.html +++ b/web_app/templates/home.html @@ -1,4 +1,6 @@ -{% extends "layout.html" %} +{% extends "bootstrap_5_layout.html" %} +{% set active_page = "home" %} + {% block content %} diff --git a/web_app/templates/stocks_dashboard.html b/web_app/templates/stocks_dashboard.html index 7b56130..e46725b 100644 --- a/web_app/templates/stocks_dashboard.html +++ b/web_app/templates/stocks_dashboard.html @@ -1,4 +1,5 @@ -{% extends "layout.html" %} +{% extends "bootstrap_5_layout.html" %} +{% set active_page = "stocks_dashboard" %} {% block content %} diff --git a/web_app/templates/stocks_form.html b/web_app/templates/stocks_form.html index d012f8f..ad12023 100644 --- a/web_app/templates/stocks_form.html +++ b/web_app/templates/stocks_form.html @@ -1,5 +1,6 @@ -{% extends "layout.html" %} +{% extends "bootstrap_5_layout.html" %} +{% set active_page = "stocks_form" %} {% block content %} @@ -15,7 +16,7 @@

Stocks Form


- + {% endblock %} From 78c29609f2b99643a9bf5af24383d8db982fbfe1 Mon Sep 17 00:00:00 2001 From: MJ Rossetti Date: Tue, 18 Apr 2023 11:58:57 -0400 Subject: [PATCH 3/5] Prepare for production deploy --- requirements.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requirements.txt b/requirements.txt index 0df88b3..1341339 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,6 @@ Flask # for testing: pytest beautifulsoup4 + +# for the production server: +gunicorn From b8049f45001df23f43140709532ca62854a02fd1 Mon Sep 17 00:00:00 2001 From: MJ Rossetti Date: Thu, 20 Apr 2023 11:40:01 -0400 Subject: [PATCH 4/5] Pass other variables to the page --- web_app/routes/home_routes.py | 2 +- web_app/templates/hello.html | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/web_app/routes/home_routes.py b/web_app/routes/home_routes.py index 45bf3f0..8c206bc 100644 --- a/web_app/routes/home_routes.py +++ b/web_app/routes/home_routes.py @@ -28,4 +28,4 @@ def hello_world(): message = f"Hello, {name}!" #return message - return render_template("hello.html", message=message) + return render_template("hello.html", message=message, other="YEAH", x=5) diff --git a/web_app/templates/hello.html b/web_app/templates/hello.html index bd60482..7c2863f 100644 --- a/web_app/templates/hello.html +++ b/web_app/templates/hello.html @@ -8,4 +8,8 @@

{{ message }}

This is a paragraph on the "hello" page.

+

Anything we want... {{ other }}

+ +

Also... {{ x }}

+ {% endblock %} From 225847c470c48f137e21ff5614be246c61c2ac08 Mon Sep 17 00:00:00 2001 From: MJ Rossetti Date: Thu, 20 Apr 2023 13:11:40 -0400 Subject: [PATCH 5/5] Unemployment Dashboard --- web_app/routes/dashboard_routes.py | 20 +++++++ web_app/services/alpha.py | 11 ++++ web_app/templates/bootstrap_5_layout.html | 3 +- web_app/templates/stocks_form.html | 1 + web_app/templates/unemployment_dashboard.html | 55 +++++++++++++++++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 web_app/templates/unemployment_dashboard.html diff --git a/web_app/routes/dashboard_routes.py b/web_app/routes/dashboard_routes.py index a2916e7..e7647da 100644 --- a/web_app/routes/dashboard_routes.py +++ b/web_app/routes/dashboard_routes.py @@ -38,3 +38,23 @@ def stocks_dashboard(): print("ERROR", err) #flash("OOPS", "warning") return redirect("/stocks/form") + + + +@dashboard_routes.route("/unemployment/dashboard") +def unemployment_dashboard(): + print("UNEMPLOYMENT DASHBOARD...") + + try: + alpha = AlphavantageService() + df = alpha.fetch_unemployment() + if not df.empty: + data = df.to_dict("records") # convert data to list of dictionaries (JSON stucture) + return render_template("unemployment_dashboard.html", data=data) + else: + #flash("OOPS", "warning") + return redirect("/") + except Exception as err: + print("ERROR", err) + #flash("OOPS", "warning") + return redirect("/") diff --git a/web_app/services/alpha.py b/web_app/services/alpha.py index cc076e0..b44c41c 100644 --- a/web_app/services/alpha.py +++ b/web_app/services/alpha.py @@ -44,6 +44,17 @@ def fetch_stocks_daily(self, symbol="MSFT"): else: return df + def fetch_unemployment(self): + """ + Fetches unemployment data. + Returns the data, or an empty DataFrame if none is available. + """ + request_url = f"https://www.alphavantage.co/query?function=UNEMPLOYMENT&apikey={self.api_key}&datatype=csv" + df = read_csv(request_url) #> pandas.DataFrame + if "timestamp" not in df.columns: + return DataFrame() + else: + return df diff --git a/web_app/templates/bootstrap_5_layout.html b/web_app/templates/bootstrap_5_layout.html index 756200b..af66574 100644 --- a/web_app/templates/bootstrap_5_layout.html +++ b/web_app/templates/bootstrap_5_layout.html @@ -39,7 +39,8 @@ {% set nav_links = [ ('/about', 'about', 'About'), ('/hello', 'hello', 'Hello'), - ('/stocks/form', 'stocks_form', 'Stocks Form') + ('/stocks/form', 'stocks_form', 'Stocks Form'), + ('/unemployment/dashboard', 'unemployment_dashboard', 'Unemployment Dashboard') ] -%} {% set active_page = active_page|default('home') -%}