-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (70 loc) · 3.01 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
from flask import Flask, render_template, request, redirect, url_for, jsonify
from CryptoModelV2 import formatTimeDataWithTime, predictCrypto
from PriceRetriever import headingGetter as getCryptoData
from PriceRetriever import roundCrypto, formatLargeNumber, roundCryptoWithoutDollar, priceGreed
app = Flask(__name__)
global name, symbol, price, pchange_1h, pchange_24h, pchange_7d, pchange_30d, pchange_60d, pchange_90d, market_cap
global x_real, y_real, x_predicted, y_predicted
@app.route("/")
def home():
return render_template("index.html")
@app.route("/index.html")
def index():
return render_template("index.html")
@app.route("/dashboard.html", methods=['POST', 'GET'])
def dashboard():
if request.method == 'POST':
coinName = request.form['coinName']
return redirect("/dashboard.html?token="+coinName, code=302)
try:
coinName = request.args.get("token")
try:
name, symbol, price, pchange_1h, pchange_24h, pchange_7d, pchange_30d, pchange_60d, pchange_90d, market_cap = getCryptoData(
coinName)
x_real, y_real, x_predicted, y_predicted = predictCrypto(symbol, daysToPredict=180)
price = roundCrypto(price)
pchange_1h = roundCrypto(pchange_1h)
pchange_24h = roundCryptoWithoutDollar(pchange_24h)
pchange_7d = roundCryptoWithoutDollar(pchange_7d)
pchange_30d = roundCryptoWithoutDollar(pchange_30d)
pchange_60d = roundCryptoWithoutDollar(pchange_60d)
pchange_90d = roundCryptoWithoutDollar(pchange_90d)
market_cap = roundCrypto(market_cap)
data = {
'coin_name': name,
'coin_ticker': symbol,
'dates': x_predicted,
'historical_data': y_real,
'predicted_data': y_predicted,
'price': price,
'pchange_24h': pchange_24h,
'pchange_7d': pchange_7d,
'pchange_30d': pchange_30d,
'pchange_60d': pchange_60d,
'pchange_90d': pchange_90d,
'market_cap': market_cap
}
confidence = 0
preLast = y_predicted[len(y_predicted) - 1]
realLast = y_real[len(y_real) - 1]
if preLast <= realLast:
confidence = (1 - ((realLast - preLast) / realLast)) * 50
else:
confidence = (1 - ((realLast - preLast) / preLast)) * 50
confidence = round(confidence, 1)
fearRating, emotion = priceGreed()
return render_template("dashboardBigGraph.html", data=data, name=name,fg=fearRating,cr=confidence)
except:
print("Error")
except:
print("No token")
coinName = 'BTC'
return redirect("/dashboard.html?token=" + coinName, code=302)
@app.route("/about.html")
def about():
return render_template("about.html")
@app.route("/education.html")
def education():
return render_template("education.html")
if __name__ == '__main__':
app.run()