-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
71 lines (46 loc) · 2.25 KB
/
server.py
File metadata and controls
71 lines (46 loc) · 2.25 KB
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
from flask import Flask, render_template, request
from printCodeGen import generate_macro_code
from commonUtils import read_excel_file, log
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/', strict_slashes=False)
def home():
return render_template('home.html')
@app.route('/print', methods=['GET', 'POST'])
def print_route():
if request.method == 'POST':
sheetnumber = request.form['sheetnumber']
column = request.form['column']
xlfile = request.files['xl']
if xlfile and column and sheetnumber:
if not sheetnumber.isnumeric():
log("Please provide a numeric sheet number")
return render_template("print.html", error="Please provide a numeric sheet number")
if not column.isalpha():
log("Please provide a valid column name")
return render_template("print.html", error="Please provide a valid column name")
sheetnumber = int(sheetnumber)
column = column.upper()
vals = read_excel_file(xlfile, column=column, sheet_name=sheetnumber)
if isinstance(vals, ValueError):
log(str(vals))
return str(vals)
elif isinstance(vals, Exception):
log(str(vals))
return render_template("print.html", error="Unknow error occured\n"+str(vals))
code = generate_macro_code(vals)
if isinstance(code, TypeError):
return render_template("print.html", error="The quantity column contains non-numeric values\n"+str(code))
elif isinstance(code, Exception):
return render_template("print.html", error="Unknow error occured\n"+str(code))
print(code)
return render_template("print.html", code=code)
else:
return render_template("print.html", error="No excel file attached")
return render_template('print.html')
@app.route('/testing')
def testing():
return 'asjihdiohdua huei9wa eajsnjaiehw8 aihdajhw0d a90oaidji2ojeiojd aouw9-e a90uw09 assdhh'
if __name__ == '__main__':
app.run(debug=True, port=5322)