6 Commits

Author SHA1 Message Date
d3m1g0d
e3231095c4 Merge branch 'Testing-json' of https://github.com/d3m1g0d/TeraHz into Testing-json 2019-03-26 19:06:42 +01:00
d3m1g0d
9d3a3419c8 fuck me. 2019-03-26 19:06:00 +01:00
d3m1g0d
548337258f simplifying a lot of shit 2019-03-26 19:05:42 +01:00
ANormalPerson1
51d6695fec Attempting request.post and request.get_json
Attempting to understand what the various methods do, do to differing documentation on some parts.
To current knowledge, get_json gets a json file from the webserver, whilst post uploads one. On to how to access the uploaded json with html, I will work on.
2019-03-23 10:20:53 +01:00
ANormalPerson1
d938937d48 request.json -> request.get_json()
Apparently, the json method of request is considered deprecated, src https://stackoverflow.com/questions/20001229/how-to-get-posted-json-in-flask
So swallep it out for request.get_json
2019-03-23 09:50:40 +01:00
ANormalPerson1
9677273f55 Attempt at doing json
I fucked up big time. I have attempted to make a custom made chart, while, to my knowledge, one is readily available and more easily incorporated to the website design.
2019-03-21 21:18:05 +01:00
9 changed files with 88 additions and 5 deletions

9
backend/graph.js Normal file
View File

@@ -0,0 +1,9 @@
$(document).ready(function() {
$(chart_id).highcharts({
chart: chart,
title: title,
xAxis: xAxis,
yAxis: yAxis,
series: series
});
});

View File

@@ -1,5 +1,6 @@
from flask import Flask, redirect, url_for, request
from flask import Flask, redirect, url_for, request, render_template
app = Flask(__Name__)
URL = "" #Insert url of website here
@app.route('/list')
def list():
@@ -13,4 +14,21 @@ def load():
def deposit():
#Request .json, store json
if request.isJson():
request.json.
content = request.get_json(url = URL)
return content
@app.route('/post', , methods = ['POST']):
def post():
request.post(url = URL, data = "") #Insert the data you wish to upload
@app.route('/graph')
def graph(chartID = 'chart_ID', chart_type = 'line', chart_height = 500):
chart = {"renderTo": chartID, "type": chart_type, "height": chart_height,}
series = [{"name": 'Label1', "data": [1,2,3]}, {"name": 'Label2', "data": [4, 5, 6]}]
title = {"text": 'My Title'}
xAxis = {"categories": ['xAxis Data1', 'xAxis Data2', 'xAxis Data3']}
yAxis = {"title": {"text": 'yAxis Label'}}
return render_template('index.html', chartID=chartID, chart=chart, series=series, title=title, xAxis=xAxis, yAxis=yAxis)
if __name__ == "__main__":
app.run(debug = True, host='0.0.0.0', port=8080, passthrough_errors=True)

View File

@@ -73,7 +73,7 @@ class Spectrometer:
self.baudrate = baudrate
self.timeout = 1
try:
self.serialObject = ser.Serial(path, baudrate, timeout=tout)
self.serialObject =
except:
raise Exception('An exception occured when opening the serial port at {}'.format(path))
ex(1)

Binary file not shown.

6
flask-testing/hello1.py Normal file
View File

@@ -0,0 +1,6 @@
from flask import Flask
app = Flask(__name__)
@app.route('/<txt>')
def root(txt):
return 'txt={}'.format(txt)

14
frontend/FlaskModule.py Normal file
View File

@@ -0,0 +1,14 @@
from flask import Flask
app = Flask(__name__)
@app.route('/', methods = ['GET', 'POST'])
def index():
value = request.json['key']
return value
if __name__ == '__main__':
app.run
test = open("JsonJs", "r")
req = requests.post('C:/Users/Janez%20Dolzan/Documents/Python%20projects/Spektrometer/GitHub/TeraHz/frontend/website.html')

1
frontend/JsonJs.js Normal file
View File

@@ -0,0 +1 @@
var output = document.getElementById('output');

17
frontend/org.json Normal file
View File

@@ -0,0 +1,17 @@
{
"org":
[
{
"id": 1,
"name": "How to build a website"
},
{
"id": 2,
"name": "How to build a website 2"
},
{
"id": 2,
"name": "How to build a website 3"
}
]
}

View File

@@ -18,11 +18,29 @@
<button type="button" class="btn btn-dark btn-lg btn-block">Pridobi rezultate
</div>
<div id={{ chartID|safe }} class="chart" style="height: 100px; width: 500px"></div>
<script>
var chart_id = {{ chartID|safe }}
var series = {{ series|safe }}
var title = {{ title|safe }}
var xAxis = {{ xAxis|safe }}
var yAxis = {{ yAxis|safe }}
var chart = {{ chart|safe }}
</script>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="../static/graph.js"></script>
</body>
<script type = "text/javascript" src = "/static/bootstrap.min.js"></script>
</html>