85 lines
2.0 KiB
Python
85 lines
2.0 KiB
Python
from flask import Flask, render_template, request
|
|
import sys
|
|
import os
|
|
from streamer import stream_gcode
|
|
import svgToGcode
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
ALLOWED_EXTENSIONS_SVG_FORM = {'svg'}
|
|
ALLOWED_EXTENSIONS_GCODE_FORM = {'gcode'}
|
|
|
|
|
|
def allowed_file_svg(filename):
|
|
return '.' in filename and \
|
|
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS_SVG_FORM
|
|
|
|
def allowed_file_gcode(filename):
|
|
return '.' in filename and \
|
|
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS_GCODE_FORM
|
|
|
|
|
|
|
|
@app.route("/", methods=["POST", "GET"])
|
|
def index():
|
|
return render_template("form.html")
|
|
|
|
|
|
|
|
|
|
@app.route("/svg_file", methods=["POST", "GET"])
|
|
def getSVG():
|
|
|
|
if request.method == "POST":
|
|
|
|
file = request.files.get("file")
|
|
if file and allowed_file_svg(file.filename):
|
|
|
|
output = 'gcode_output.gcode'
|
|
|
|
gcode = svgToGcode.convertToGcode(file.read() ,output)
|
|
|
|
stream_gcode(gcode.splitlines())
|
|
print(gcode)
|
|
print("done!")
|
|
else:
|
|
print('unaccepted file')
|
|
|
|
|
|
return render_template("form.html")
|
|
|
|
@app.route("/gcode_file", methods=["POST", "GET"])
|
|
def getGcode():
|
|
|
|
if request.method == "POST":
|
|
|
|
file = request.files.get("file")
|
|
|
|
if file and allowed_file_gcode(file.filename):
|
|
|
|
gcode = file.readlines()
|
|
print(str(gcode))
|
|
stream_gcode(gcode)
|
|
|
|
else:
|
|
print('empty file or unaccepted file')
|
|
|
|
return render_template("form.html")
|
|
|
|
@app.route("/text", methods=["POST", "GET"])
|
|
def getText():
|
|
if request.method == "POST":
|
|
txt = request.form["txt"]
|
|
size_txt = txt.count()
|
|
if txt:
|
|
# print(txt)
|
|
print(size-txt)
|
|
|
|
else:
|
|
print('empty text')
|
|
return render_template("form.html")
|
|
|
|
|
|
|