From 2868418e7c20861f12a581e132dbb5b26fffb358 Mon Sep 17 00:00:00 2001 From: reese bearden Date: Mon, 2 Aug 2021 11:05:12 -0500 Subject: [PATCH 1/6] test --- .azure/config | 7 + app.py | 107 ++++++++++++- dashboard.html | 39 +++++ hist_data_func.py | 61 ++++++++ key.txt | 4 + materialize | 1 + static/css/signup.css | 0 static/js/chart.js | 3 + templates/404.jinja2 | 7 + templates/base.jinja2 | 25 ++++ templates/create.jinja2 | 20 +++ templates/dashboard.html | 313 +++++++++++++++++++++++++++++++++++++++ templates/home.jinja2 | 14 ++ templates/post.jinja2 | 6 + templates/sign_up.html | 25 ++++ templates/stocks.html | 17 +++ 16 files changed, 645 insertions(+), 4 deletions(-) create mode 100644 .azure/config create mode 100644 dashboard.html create mode 100644 hist_data_func.py create mode 100644 key.txt create mode 160000 materialize create mode 100644 static/css/signup.css create mode 100644 static/js/chart.js create mode 100644 templates/404.jinja2 create mode 100644 templates/base.jinja2 create mode 100644 templates/create.jinja2 create mode 100644 templates/dashboard.html create mode 100644 templates/home.jinja2 create mode 100644 templates/post.jinja2 create mode 100644 templates/sign_up.html create mode 100644 templates/stocks.html diff --git a/.azure/config b/.azure/config new file mode 100644 index 000000000..4b003227a --- /dev/null +++ b/.azure/config @@ -0,0 +1,7 @@ +[defaults] +group = resourcegroup1 +sku = P1v2 +appserviceplan = ASP-resourcegroup1-bed7 +location = centralus +web = moonscreen + diff --git a/app.py b/app.py index 7f8a1f2e8..c2192d5f0 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,105 @@ -from flask import Flask +from flask import Flask, render_template, request, redirect, url_for +import requests +import os +import json +import pandas as pd +import numpy as np + app = Flask(__name__) +posts = { + 0: { + 'title': 'Hello, world', + 'content': 'This is my first blog post!' + } +} + +tickers = { + 0: { + 'symbol': 'MSFT' + }, + 1: { + 'symbol': 'AAPL' + }, + 2: { + 'symbol': 'DXCM' + } +} + + +@app.route('/') +def home(): + return render_template('home.jinja2', posts=posts) + + +@app.route('/post/') +def post(post_id): + post = posts.get(post_id) + if not post: + return render_template('404.jinja2', message=f'A post with id {post_id} was not found.') + return render_template('post.jinja2', post=post) + + +@app.route('/post/create', methods=['GET', 'POST']) +def create(): + if request.method == 'POST': + title = request.form.get('title') + content = request.form.get('content') + post_id = len(posts) + posts[post_id] = {'id': post_id, 'title': title, 'content': content} + + return redirect(url_for('post', post_id=post_id)) + return render_template('create.jinja2') + + +@app.route('/sign_up') +def sign_up(): + return render_template('sign_up.html') + + +@app.route('/stocks', methods=['GET', 'POST']) +def stocks(): + symbol = request.args.get('symbol') + ticker_id = len(tickers) + tickers[ticker_id] = {'id': ticker_id, 'symbol': symbol} + return render_template('stocks.html', tickers=tickers) + + + +os.chdir("/Users/astralconvict/python-docs-hello-world") + +# retrieve from +endpoint = 'https://data.alpaca.markets/v2' +key = json.loads(open("key.txt", 'r').read()) + +symbol = "aapl" +bar_url = endpoint + "/stocks/{}/bars".format(symbol) +params = {"start": "2021-07-20", + "limit": 600, + "timeframe": "1Day" + } + +@app.route('/stock-data') +def stock_data(): + data = {"bars": [], "next_page_token": '', "symbol": symbol} + while True: + r = requests.get(bar_url, headers=key, params=params) + r = r.json() + if r["next_page_token"] is None: + data["bars"] += r["bars"] + break + else: + params["page_token"] = r["next_page_token"] + data["bars"] += r["bars"] + data["next_page_token"] = r["next_page_token"] + return render_template("dashboard.html", data=data) + + + + + +if __name__ == '__main__': + app.run(debug=True) + -@app.route("/") -def hello(): - return "Hello, World!" +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/dashboard.html b/dashboard.html new file mode 100644 index 000000000..674a03fc7 --- /dev/null +++ b/dashboard.html @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Model:Decision TreeRegressionRandom
Predicted:TumourNon-TumourTumourNon-TumourTumourNon-Tumour
38.02.018.022.021NaN
19.0439.06.0452.0226232.0
\ No newline at end of file diff --git a/hist_data_func.py b/hist_data_func.py new file mode 100644 index 000000000..9e1386ffd --- /dev/null +++ b/hist_data_func.py @@ -0,0 +1,61 @@ +# from flask import Blueprint +# import requests +# import os +# import json +# import pandas as pd + +# views = Blueprint('views', __name__) + + +# os.chdir("/Users/astralconvict/python-docs-hello-world") + +# # retrieve from +# endpoint = 'https://data.alpaca.markets/v2' +# key = json.loads(open("key.txt", 'r').read()) + +# symbol = input() +# bar_url = endpoint + "/stocks/{}/bars".format(symbol) +# params = {"start": "2020-06-27", +# "limit": 600, +# "timeframe": "1Day" +# } + + +# def hist_data(symbols, start="2021-05-05", timeframe="1Hour", limit=600, end=""): +# df_data_tickers = {} + +# r = requests.get(bar_url, headers=key, params=params) +# json_dump = r.json() +# for symbol in json_dump: +# temp = pd.DataFrame(json_dump[symbols]) +# temp.rename({"t": "time", "o": "open", "h": "high", "l": "low", "c": "close", "v": "volume"}, axis=1, +# inplace=True) +# temp["time"] = pd.to_datetime(temp["time"], unit="s") +# temp.set_index("time", inplace=True) +# temp.index = temp.index.tz_localize("UTC").tz_convert("America/Detroit") +# return temp + + +# @views.route('/stock-data') +# def stock_data(): +# data = {"bars": [], "next_page_token": '', "symbol": symbol} +# while True: +# r = requests.get(bar_url, headers=key, params=params) +# r = r.json() +# if r["next_page_token"] is None: +# data["bars"] += r["bars"] +# break +# else: +# params["page_token"] = r["next_page_token"] +# data["bars"] += r["bars"] +# data["next_page_token"] = r["next_page_token"] + +# df_data = pd.DataFrame(data["bars"]) +# df_data.rename({"t": "time", "o": "open", "h": "high", "l": "low", "c": "close", "v": "volume"}, axis=1, +# inplace=True) +# df_data["time"] = pd.to_datetime(df_data["time"]) +# df_data.set_index("time", inplace=True) +# df_data.index = df_data.index.tz_convert("America/Detroit") +# print(df_data) + + diff --git a/key.txt b/key.txt new file mode 100644 index 000000000..c8f9ac94b --- /dev/null +++ b/key.txt @@ -0,0 +1,4 @@ +{ +"APCA-API-KEY-ID": "PK59YESDJMIFFHINXMXY", +"APCA-API-SECRET-KEY": "0bhh4rRTDJxXbQTSmjzL3W4wTpf3qaQAoPpMcHNN" +} \ No newline at end of file diff --git a/materialize b/materialize new file mode 160000 index 000000000..824e78248 --- /dev/null +++ b/materialize @@ -0,0 +1 @@ +Subproject commit 824e78248b3de81e383445e76ffb04cc3264fe7d diff --git a/static/css/signup.css b/static/css/signup.css new file mode 100644 index 000000000..e69de29bb diff --git a/static/js/chart.js b/static/js/chart.js new file mode 100644 index 000000000..715f24c46 --- /dev/null +++ b/static/js/chart.js @@ -0,0 +1,3 @@ +function myFunc(vars) { + return vars; +} \ No newline at end of file diff --git a/templates/404.jinja2 b/templates/404.jinja2 new file mode 100644 index 000000000..28944114e --- /dev/null +++ b/templates/404.jinja2 @@ -0,0 +1,7 @@ +{% extends 'base.jinja2' %} + +{% block content %} +

404 - Post not found

+

{{ message }}

+{% endblock %} + diff --git a/templates/base.jinja2 b/templates/base.jinja2 new file mode 100644 index 000000000..e5cf2717e --- /dev/null +++ b/templates/base.jinja2 @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + +home +{% block content %} + +{% endblock %} + + + + \ No newline at end of file diff --git a/templates/create.jinja2 b/templates/create.jinja2 new file mode 100644 index 000000000..476f936ae --- /dev/null +++ b/templates/create.jinja2 @@ -0,0 +1,20 @@ +{% extends 'base.jinja2' %} + +{% block content %} +

Create post

+
+
+ + +
+ +
+ + +
+ +
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/dashboard.html b/templates/dashboard.html new file mode 100644 index 000000000..ba7c1f5c4 --- /dev/null +++ b/templates/dashboard.html @@ -0,0 +1,313 @@ +{% extends 'base.jinja2' %} +{% block content %} + + + + + + + + + + + + + + + + {% for d in data["bars"] %} + + + + + + + + + {% endfor %} + +
timeopen pricehighlowclosing pricevolume
{{d["t"]}}{{d["o"]}}{{d["h"]}}{{d["l"]}}{{d["c"]}}{{d["v"]}}
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/home.jinja2 b/templates/home.jinja2 new file mode 100644 index 000000000..fa3385774 --- /dev/null +++ b/templates/home.jinja2 @@ -0,0 +1,14 @@ +{% extends 'base.jinja2' %} + +{% block content %} +

Welcome to your blog.

+

Posts

+ + +Create Post + +{% endblock %} \ No newline at end of file diff --git a/templates/post.jinja2 b/templates/post.jinja2 new file mode 100644 index 000000000..c0a2e7652 --- /dev/null +++ b/templates/post.jinja2 @@ -0,0 +1,6 @@ +{% extends 'base.jinja2' %} + +{% block content %} +

{{ post['title'] }}

+

{{ post['content'] }}

+{% endblock %} \ No newline at end of file diff --git a/templates/sign_up.html b/templates/sign_up.html new file mode 100644 index 000000000..230ed1e7e --- /dev/null +++ b/templates/sign_up.html @@ -0,0 +1,25 @@ +{% extends 'base.jinja2' %} + +{% block content %} + +
+

Sign Up

+
+ +
+
+ account_circle + + +
+
+ phone + + +
+
+ +
+ + +{% endblock %} \ No newline at end of file diff --git a/templates/stocks.html b/templates/stocks.html new file mode 100644 index 000000000..8055e113d --- /dev/null +++ b/templates/stocks.html @@ -0,0 +1,17 @@ +{% extends 'base.jinja2' %} + +{% block content %} +{% for ticker_id, ticker in tickers.items() %} +
  • {{ tickers[ticker_id]['symbol'] }}
  • +{% endfor %} +
    +
    + + + +
    +
    + +{% endblock %} \ No newline at end of file From 03dd5542b7b53d42ac0056ef4017a2897f8971d9 Mon Sep 17 00:00:00 2001 From: reese bearden Date: Sat, 7 Aug 2021 19:46:56 -0500 Subject: [PATCH 2/6] chart now pulls in data from alpaca and shows accurate historical data --- app.py | 9 +- templates/dashboard.html | 313 ------------------------------------- templates/dashboard.jinja2 | 138 ++++++++++++++++ 3 files changed, 144 insertions(+), 316 deletions(-) delete mode 100644 templates/dashboard.html create mode 100644 templates/dashboard.jinja2 diff --git a/app.py b/app.py index c2192d5f0..0c69fc3fc 100644 --- a/app.py +++ b/app.py @@ -71,9 +71,9 @@ def stocks(): endpoint = 'https://data.alpaca.markets/v2' key = json.loads(open("key.txt", 'r').read()) -symbol = "aapl" +symbol = "msft" bar_url = endpoint + "/stocks/{}/bars".format(symbol) -params = {"start": "2021-07-20", +params = {"start": "2020-07-20", "limit": 600, "timeframe": "1Day" } @@ -81,9 +81,11 @@ def stocks(): @app.route('/stock-data') def stock_data(): data = {"bars": [], "next_page_token": '', "symbol": symbol} + dataTime = ["test"] while True: r = requests.get(bar_url, headers=key, params=params) r = r.json() + dataTime += r["bars"][0]["t"] if r["next_page_token"] is None: data["bars"] += r["bars"] break @@ -91,7 +93,8 @@ def stock_data(): params["page_token"] = r["next_page_token"] data["bars"] += r["bars"] data["next_page_token"] = r["next_page_token"] - return render_template("dashboard.html", data=data) + + return render_template("dashboard.jinja2", data=data, dataTime=dataTime) diff --git a/templates/dashboard.html b/templates/dashboard.html deleted file mode 100644 index ba7c1f5c4..000000000 --- a/templates/dashboard.html +++ /dev/null @@ -1,313 +0,0 @@ -{% extends 'base.jinja2' %} -{% block content %} - - - - - - - - - - - - - - - - {% for d in data["bars"] %} - - - - - - - - - {% endfor %} - -
    timeopen pricehighlowclosing pricevolume
    {{d["t"]}}{{d["o"]}}{{d["h"]}}{{d["l"]}}{{d["c"]}}{{d["v"]}}
    - - - -{% endblock %} \ No newline at end of file diff --git a/templates/dashboard.jinja2 b/templates/dashboard.jinja2 new file mode 100644 index 000000000..030129df6 --- /dev/null +++ b/templates/dashboard.jinja2 @@ -0,0 +1,138 @@ +{% extends 'base.jinja2' %} +{% block content %} + + + +{% endblock %} \ No newline at end of file From d6ab820f89c4225180fc0d733e9196c4d7b76b49 Mon Sep 17 00:00:00 2001 From: reese bearden Date: Sat, 7 Aug 2021 19:51:58 -0500 Subject: [PATCH 3/6] chart now pulls in data from alpaca and shows accurate historical data --- app.py | 9 +- templates/dashboard.html | 313 ------------------------------------- templates/dashboard.jinja2 | 138 ++++++++++++++++ 3 files changed, 144 insertions(+), 316 deletions(-) delete mode 100644 templates/dashboard.html create mode 100644 templates/dashboard.jinja2 diff --git a/app.py b/app.py index c2192d5f0..0c69fc3fc 100644 --- a/app.py +++ b/app.py @@ -71,9 +71,9 @@ def stocks(): endpoint = 'https://data.alpaca.markets/v2' key = json.loads(open("key.txt", 'r').read()) -symbol = "aapl" +symbol = "msft" bar_url = endpoint + "/stocks/{}/bars".format(symbol) -params = {"start": "2021-07-20", +params = {"start": "2020-07-20", "limit": 600, "timeframe": "1Day" } @@ -81,9 +81,11 @@ def stocks(): @app.route('/stock-data') def stock_data(): data = {"bars": [], "next_page_token": '', "symbol": symbol} + dataTime = ["test"] while True: r = requests.get(bar_url, headers=key, params=params) r = r.json() + dataTime += r["bars"][0]["t"] if r["next_page_token"] is None: data["bars"] += r["bars"] break @@ -91,7 +93,8 @@ def stock_data(): params["page_token"] = r["next_page_token"] data["bars"] += r["bars"] data["next_page_token"] = r["next_page_token"] - return render_template("dashboard.html", data=data) + + return render_template("dashboard.jinja2", data=data, dataTime=dataTime) diff --git a/templates/dashboard.html b/templates/dashboard.html deleted file mode 100644 index ba7c1f5c4..000000000 --- a/templates/dashboard.html +++ /dev/null @@ -1,313 +0,0 @@ -{% extends 'base.jinja2' %} -{% block content %} - - - - - - - - - - - - - - - - {% for d in data["bars"] %} - - - - - - - - - {% endfor %} - -
    timeopen pricehighlowclosing pricevolume
    {{d["t"]}}{{d["o"]}}{{d["h"]}}{{d["l"]}}{{d["c"]}}{{d["v"]}}
    - - - -{% endblock %} \ No newline at end of file diff --git a/templates/dashboard.jinja2 b/templates/dashboard.jinja2 new file mode 100644 index 000000000..030129df6 --- /dev/null +++ b/templates/dashboard.jinja2 @@ -0,0 +1,138 @@ +{% extends 'base.jinja2' %} +{% block content %} + + + +{% endblock %} \ No newline at end of file From 47cd2ebf9f304f674be1720e526be72550716be8 Mon Sep 17 00:00:00 2001 From: reese bearden Date: Sat, 7 Aug 2021 19:58:51 -0500 Subject: [PATCH 4/6] Merge branch 'master' of https://github.com/reesebearden-student/python-docs-hello-world --- templates/dashboard.jinja2 | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/dashboard.jinja2 b/templates/dashboard.jinja2 index 030129df6..c1d78b94d 100644 --- a/templates/dashboard.jinja2 +++ b/templates/dashboard.jinja2 @@ -20,6 +20,7 @@ }); switcherElement.appendChild(itemEl); return itemEl; + // test }); function onItemClicked(item) { From 23eb9e14b767dc394bdef6a96b8af62c9116edb5 Mon Sep 17 00:00:00 2001 From: reese bearden Date: Sat, 7 Aug 2021 20:41:07 -0500 Subject: [PATCH 5/6] new changes --- templates/dashboard.jinja2 | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/dashboard.jinja2 b/templates/dashboard.jinja2 index c1d78b94d..af36c82ce 100644 --- a/templates/dashboard.jinja2 +++ b/templates/dashboard.jinja2 @@ -1,5 +1,6 @@ {% extends 'base.jinja2' %} {% block content %} +{# htbhtg #}