-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic version of flask app. Will ned to improve upon
- Loading branch information
Showing
9 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,6 @@ | |
| # ignore drafts | ||
| 01-basic-deployment-new/* | ||
| 02-advanced-deployment-old/* | ||
|
|
||
| # ignore all files that are .env | ||
| *.env | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Base image | ||
| FROM python:3.11 | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy requirements and install | ||
| COPY requirements.txt . | ||
| RUN pip install -r requirements.txt | ||
|
|
||
| # Copy all files | ||
| COPY . . | ||
|
|
||
| # Expose port for Flask | ||
| EXPOSE 5000 | ||
|
|
||
| # Run Flask app | ||
| CMD ["python", "flask_app/app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| version: '3' | ||
| services: | ||
| flask_app: | ||
| build: . | ||
| ports: | ||
| - "5000:5000" | ||
| env_file: | ||
| - .env | ||
| networks: | ||
| - 02-advanced-deployment_mynetwork | ||
|
|
||
| networks: | ||
| 02-advanced-deployment_mynetwork: | ||
| external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import os | ||
| from flask import Flask, render_template | ||
| from sqlalchemy import create_engine | ||
| import pandas as pd | ||
| from dotenv import load_dotenv | ||
|
|
||
| # Load environment variables from .env file | ||
| load_dotenv() | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
| # Retrieve the database URL from environment variables | ||
| DATABASE_URL = os.getenv('DATABASE_URL') | ||
| engine = create_engine(DATABASE_URL) | ||
|
|
||
| @app.route('/') | ||
| def index(): | ||
| # Fetch data from database | ||
| query = "SELECT * FROM weather LIMIT 10;" | ||
| df = pd.read_sql(query, engine) | ||
|
|
||
| # Convert data to HTML table | ||
| data = df.to_html(classes='table table-striped') | ||
|
|
||
| return render_template('index.html', table=data) | ||
|
|
||
| if __name__ == '__main__': | ||
| app.run(host='0.0.0.0', port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| } | ||
|
|
||
| .container { | ||
| width: 80%; | ||
| margin: auto; | ||
| } | ||
|
|
||
| table { | ||
| width: 100%; | ||
| border-collapse: collapse; | ||
| } | ||
|
|
||
| th, td { | ||
| border: 1px solid #ddd; | ||
| padding: 8px; | ||
| } | ||
|
|
||
| th { | ||
| background-color: #f2f2f2; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Data Visualization</title> | ||
| <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}"> | ||
| </head> | ||
| <body> | ||
| <h1>Data Visualization</h1> | ||
| <div class="container"> | ||
| {{ table|safe }} | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Flask App</title> | ||
| <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}"> | ||
| </head> | ||
| <body> | ||
| {% block content %} | ||
| {% endblock %} | ||
| </body> | ||
| </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Flask==1.1.4 | ||
| Werkzeug==0.16.1 | ||
| python-dotenv==1.0.0 | ||
| pandas | ||
| numpy | ||
| sqlalchemy==2.0.0 | ||
| psycopg2-binary==2.9.6 | ||
| markupsafe==2.0.1 |