Skip to content

Commit

Permalink
Created flask web app and docker container for it
Browse files Browse the repository at this point in the history
  • Loading branch information
rishavnandi committed Mar 11, 2023
1 parent 93076cc commit 38b7674
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3-slim

WORKDIR /app

COPY . .

RUN pip install --no-cache-dir -r requirements.txt

ENV FLASK_APP=app.py

EXPOSE 5000

CMD ["flask", "run", "--host=0.0.0.0"]
Binary file added __pycache__/app.cpython-310.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from flask import Flask, render_template, request
import yfinance as yf

app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
ticker = request.form['ticker']
stock = yf.Ticker(ticker)
df = stock.history(period='max')
return render_template('index.html', ticker=ticker, data=df.to_html(classes='table table-striped'))
return render_template('index.html')


if __name__ == '__main__':
app.run(debug=False)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yfinance
flask
63 changes: 63 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
* {
box-sizing: border-box;
}

body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}

.container {
width: 80%;
margin: 0 auto;
padding: 20px;
}

h1,
h2 {
text-align: center;
}

form {
margin: 20px 0;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}

label {
margin-right: 10px;
}

input[type="text"] {
padding: 10px;
font-size: 16px;
border: none;
border-radius: 5px;
}

button[type="submit"] {
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

button[type="submit"]:hover {
background-color: #3e8e41;
}

.graph-container {
margin-top: 20px;
display: flex;
justify-content: center;
align-items: center;
}

.table-container {
margin-top: 20px;
}
30 changes: 30 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Stock Price Graph</title>
<link
rel="stylesheet"
href="{{ url_for('static', filename='style.css') }}"
/>
</head>
<body>
<div class="container">
<h1>Stock Price Graph</h1>
<form method="post">
<label for="ticker">Enter Ticker Symbol:</label>
<input type="text" id="ticker" name="ticker" required />
<button type="submit">Submit</button>
</form>
{% if ticker %}
<div class="graph-container">
<img
src="https://finviz.com/chart.ashx?t={{ ticker }}&ty=c&ta=1&p=d&s=l"
alt="Price Graph for {{ ticker }}"
/>
</div>
<h2>{{ ticker }} Price History</h2>
<div class="table-container">{{ data|safe }}</div>
{% endif %}
</div>
</body>
</html>

0 comments on commit 38b7674

Please sign in to comment.