Skip to content

update #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .azure/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[defaults]
group = resourcegroup1
sku = P1v2
appserviceplan = ASP-resourcegroup1-bed7
location = centralus
web = moonscreen

110 changes: 106 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,108 @@
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/<int:post_id>')
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 = "msft"
bar_url = endpoint + "/stocks/{}/bars".format(symbol)
params = {"start": "2020-07-20",
"limit": 600,
"timeframe": "1Day"
}

@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
else:
params["page_token"] = r["next_page_token"]
data["bars"] += r["bars"]
data["next_page_token"] = r["next_page_token"]

return render_template("dashboard.jinja2", data=data, dataTime=dataTime)





if __name__ == '__main__':
app.run(debug=True)


@app.route("/")
def hello():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug=True)
61 changes: 61 additions & 0 deletions hist_data_func.py
Original file line number Diff line number Diff line change
@@ -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)


4 changes: 4 additions & 0 deletions key.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"APCA-API-KEY-ID": "PK59YESDJMIFFHINXMXY",
"APCA-API-SECRET-KEY": "0bhh4rRTDJxXbQTSmjzL3W4wTpf3qaQAoPpMcHNN"
}
1 change: 1 addition & 0 deletions materialize
Submodule materialize added at 824e78
Empty file added static/css/signup.css
Empty file.
3 changes: 3 additions & 0 deletions static/js/chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function myFunc(vars) {
return vars;
}
7 changes: 7 additions & 0 deletions templates/404.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends 'base.jinja2' %}

{% block content %}
<h1>404 - Post not found</h1>
<p>{{ message }}</p>
{% endblock %}

25 changes: 25 additions & 0 deletions templates/base.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>

<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>
<body>
<a href="/">home</a>
{% block content %}

{% endblock %}
<!--JavaScript at end of body for optimized loading-->
<script type="text/javascript" src="js/materialize.min.js"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions templates/create.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'base.jinja2' %}

{% block content %}
<h1>Create post</h1>
<form method="POST">
<div>
<label for="title">Title</label>
<input type="text" name="title" id="title" />
</div>

<div>
<label for="content">Content</label>
<textarea name="content" id="content"></textarea>
</div>

<div>
<input type="submit">
</div>
</form>
{% endblock %}
140 changes: 140 additions & 0 deletions templates/dashboard.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{% extends 'base.jinja2' %}
{% block content %}
{# htbhtg #}

<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script>
<script type="text/javascript">

var data = JSON.parse('{{ data["bars"] | tojson | safe }}');

function createSimpleSwitcher(items, activeItem, activeItemChangedCallback) {
var switcherElement = document.createElement('div');
switcherElement.classList.add('switcher');

var intervalElements = items.map(function(item) {
var itemEl = document.createElement('button');
itemEl.innerText = item;
itemEl.classList.add('switcher-item');
itemEl.classList.toggle('switcher-active-item', item === activeItem);
itemEl.addEventListener('click', function() {
onItemClicked(item);
});
switcherElement.appendChild(itemEl);
return itemEl;
// test
});

function onItemClicked(item) {
if (item === activeItem) {
return;
}

intervalElements.forEach(function(element, index) {
element.classList.toggle('switcher-active-item', items[index] === item);
});

activeItem = item;

activeItemChangedCallback(item);
}

return switcherElement;
}

var switcherElement = createSimpleSwitcher(['Dark', 'Light'], 'Dark', syncToTheme);

var chartElement = document.createElement('div');

var chart = LightweightCharts.createChart(chartElement, {
width: 600,
height: 300,
rightPriceScale: {
borderVisible: false,
},
timeScale: {
borderVisible: false,
},
});

document.body.appendChild(chartElement);
document.body.appendChild(switcherElement);

var areaSeries = chart.addAreaSeries({
topColor: 'rgba(33, 150, 243, 0.56)',
bottomColor: 'rgba(33, 150, 243, 0.04)',
lineColor: 'rgba(33, 150, 243, 1)',
lineWidth: 2,
});

var darkTheme = {
chart: {
layout: {
backgroundColor: '#2B2B43',
lineColor: '#2B2B43',
textColor: '#D9D9D9',
},
watermark: {
color: 'rgba(0, 0, 0, 0)',
},
crosshair: {
color: '#758696',
},
grid: {
vertLines: {
color: '#2B2B43',
},
horzLines: {
color: '#363C4E',
},
},
},
series: {
topColor: 'rgba(32, 226, 47, 0.56)',
bottomColor: 'rgba(32, 226, 47, 0.04)',
lineColor: 'rgba(32, 226, 47, 1)',
},
};

const lightTheme = {
chart: {
layout: {
backgroundColor: '#FFFFFF',
lineColor: '#2B2B43',
textColor: '#191919',
},
watermark: {
color: 'rgba(0, 0, 0, 0)',
},
grid: {
vertLines: {
visible: false,
},
horzLines: {
color: '#f0f3fa',
},
},
},
series: {
topColor: 'rgba(33, 150, 243, 0.56)',
bottomColor: 'rgba(33, 150, 243, 0.04)',
lineColor: 'rgba(33, 150, 243, 1)',
},
};

var themesData = {
Dark: darkTheme,
Light: lightTheme,
};

function syncToTheme(theme) {
chart.applyOptions(themesData[theme].chart);
areaSeries.applyOptions(themesData[theme].series);
}

for (var i = 0; i < data.length; i++)
{
areaSeries.update({ time: data[i].t.toString().substring(0,10), value: data[i].c.toString() });
}
syncToTheme('Dark');
</script>
{% endblock %}
Loading