-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
214 lines (116 loc) · 3.96 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#run direct from VSCODE environ, weird error where yfinance isn't detected
from flask import Flask, url_for, redirect, render_template_string, render_template, request
from plot.plt import graph
import yfinance as yf
import time
import os
from news.scrape import parse_source
app = Flask(__name__)
link = (parse_source()[1])
@app.route('/')
def homepage():
#use source parsing module to organize data feed on homepage of website
return render_template("main.html")
@app.route('/index', methods = ['POST', 'GET'])
def index():
#return render_template_string("H")
if request.method=='POST':
try:
stock = request.form['stock_index']
#quote = yf.Ticker(stock)
ticker_yahoo = yf.Ticker(stock)
data = ticker_yahoo.history()
last_quote = str(data['Close'].iloc[-1])
#print(data)
#return render_template_string(last_quote)
#formats so as to allow same CSS style in index
#also prevents white border error
#<meta http-equiv="refresh" content="2">
header = """
<meta name="theme-color" content="#000000">
<style>
mix-blend-mode: multiply;
.roboto-light {
font-family: "Roboto", sans-serif;
font-weight: 300;
font-style: normal;
}
footer{
color: white;
font-family: sans-serif;
background-color: #36454f;
margin:0;
}
h1{
font-family: sans-serif;
background-color: #36454f;
margin:0;
color: white;
}
h2{
font-family: sans-serif;
color: white;
background-color: #36454f;
margin:0;
body{
background-color: #36454f;
;
}
p{
background-color: #36454f;
margin:0;
}
br{
color: #36454f;
background-color: #36454f;
margin:0;
}
}
div{
margin: 0%;
}
</style>
<style type="text/css">
body { margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px
}
form{
background-color: #36454f;
color: #ffffff;
font-family: sans-serif;
border-color: #36454f;
}
</style>
<div></div>
<div id="no-background"></div>
<h1>QuantSpec</h1>
<form action="/index" method="post" autocomplete="on">
<label for="stock">Enter valid symbol</label>
<input type="ticker" name="stock_index" placeholder="ex: AMZN">
<input type="submit">
<div></div>
"""
footer = '''
<center>
<h1>Recent News:</h1>
<p>{{link}}</p>
</center>
<center>
<footer>
<div class="row justify-content-center">
<div class="col-md-7 text-center">
Copyright Matthew Anto / QuantSpec ©<script>document.write(new Date().getFullYear());</script> All rights reserved </a>
</div>
</footer>
</center>
'''
return render_template_string(header+graph(stock)+footer)
except IndexError:
return render_template("stock_not_found.html")
@app.route('/about')
def about():
return render_template("about.html")
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080)))