Skip to content

Commit 11c75c1

Browse files
authored
Merge pull request #1 from jitsejan/upgrade-python-to-3.9
Upgrade python to 3.9
2 parents 173d240 + 78c4de7 commit 11c75c1

File tree

10 files changed

+95
-256
lines changed

10 files changed

+95
-256
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
Pipfile.lock
106+
images/*.csv

Pipfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ verify_ssl = true
88
[packages]
99
matplotlib = "*"
1010
flask = "*"
11+
mypy = "*"
12+
flake8 = "*"
13+
isort = "*"
14+
black = "*"
1115

1216
[requires]
13-
python_version = "3.6"
17+
python_version = "3.9"
18+
19+
[pipenv]
20+
allow_prereleases = true

Pipfile.lock

Lines changed: 0 additions & 201 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Open http://127.0.0.1:5000/, draw a character, click on Send and watch your term
1919

2020
<img src="images/out.png" alt="image-20191206022811472" style="zoom:33%;" />
2121

22-
23-
2422
### Introduction
2523

2624
In this project I am experimenting with sending data between Javascript and Python using the web framework Flask. Additionally I will use matplotlib to generate a dynamic graph based on the provided user input data.
@@ -33,14 +31,14 @@ In this project I am experimenting with sending data between Javascript and Pyth
3331

3432
### Important bits
3533

36-
Send the `outputData` from Javascript to Python with a POST call to postmethod and use the form variable canvas_data. The POST call give a response from Python and the page is redirected to the results page with the given uuid.
34+
Send the `outputData` from Javascript to Python with a POST call to postmethod and use the form variable canvas_data. The POST call give a response from Python and the page is redirected to the results page with the given unique ID.
3735

3836
```javascript
3937
...
4038
$.post( "/postmethod", {
4139
canvas_data: JSON.stringify(outputData)
4240
}, function(err, req, resp){
43-
window.location.href = "/results/"+resp["responseJSON"]["uuid"];
41+
window.location.href = "/results/"+resp["responseJSON"]["unique_id"];
4442
});
4543
...
4644
```
@@ -49,11 +47,11 @@ Retrieve the `canvas_data` from the POST request and write the content to a file
4947

5048
```python
5149
...
52-
@app.route('/postmethod', methods = ['POST'])
50+
@app.route('/postmethod', methods=['POST'])
5351
def post_javascript_data():
5452
jsdata = request.form['canvas_data']
5553
unique_id = create_csv(jsdata)
56-
params = { 'uuid' : unique_id }
54+
params = {'unique_id': unique_id }
5755
return jsonify(params)
5856
...
5957
```
@@ -87,10 +85,10 @@ def index():
8785
return render_template('layouts/index.html',
8886
title=title)
8987

90-
@app.route('/results/<uuid>', methods=['GET'])
91-
def results(uuid):
88+
@app.route('/results/<unique_id>', methods=['GET'])
89+
def results(unique_id):
9290
title = 'Result'
93-
data = get_file_content(uuid)
91+
data = get_file_content(unique_id)
9492
return render_template('layouts/results.html',
9593
title=title,
9694
data=data)
@@ -99,7 +97,7 @@ def results(uuid):
9997
def post_javascript_data():
10098
jsdata = request.form['canvas_data']
10199
unique_id = create_csv(jsdata)
102-
params = { 'uuid' : unique_id }
100+
params = { 'unique_id' : unique_id }
103101
return jsonify(params)
104102

105103
@app.route('/plot/<imgdata>')
@@ -123,8 +121,8 @@ def create_csv(text):
123121
file.write(text[1:-1]+"\n")
124122
return unique_id
125123

126-
def get_file_content(uuid):
127-
with open('images/'+uuid+'.csv', 'r') as file:
124+
def get_file_content(unique_id):
125+
with open('images/'+unique_id+'.csv', 'r') as file:
128126
return file.read()
129127

130128
if __name__ == '__main__':
@@ -199,7 +197,7 @@ $( document ).ready(function() {
199197
$.post( "/postmethod", {
200198
canvas_data: JSON.stringify(outputData)
201199
}, function(err, req, resp){
202-
window.location.href = "/results/"+resp["responseJSON"]["uuid"];
200+
window.location.href = "/results/"+resp["responseJSON"]["unique_id"];
203201
});
204202
}
205203

0 commit comments

Comments
 (0)