diff --git a/app.py b/app.py index 884defea98c89721380ba1b0217226d71f3bf98c..d010bf9c87f792ffe2f9e4c537f72bddb877f9bf 100644 --- a/app.py +++ b/app.py @@ -6,7 +6,7 @@ import sys import tempfile import io import requests -# from svg_to_hpgl import svgToHPGL +from svg_to_hpgl import svgToHPGL app = Flask(__name__) @@ -157,7 +157,7 @@ def drawing(id): ascii_input = pad_export.text # to SVG - svg = ascii2svg(ascii_input, params['weight']); + svg = ascii2svg(ascii_input, params['weight']) return render_template( 'drawing.html', @@ -226,10 +226,22 @@ def catalogue(): def make_svg (): return '' -@app.route('/hpgl/') -def hpgl (): - # generate svg - svg = make_svg() +@app.route('/hpgl/<id>') +def hpgl (id): + params = { + 'pad': id or 'default', + 'weight': request.args.get('w') or '3', + } + params['pad-full'] = etherpad + prefix + params['pad'] + + # get pad content + print(' getting ' + params['pad-full']) + pad_export = requests.get(params['pad-full'] + '/export/txt') + ascii_input = pad_export.text + + # to SVG + svg = ascii2svg(ascii_input, params['weight']) + # store as a temporary file (svg_file, svg_path) = tempfile.mkstemp() svg_file.write(svg) @@ -241,11 +253,9 @@ def hpgl (): os.remove(svg_path) r = Response(hpgl, mimetype='application/hpgl') - r.headers.extend({ 'Content-Disposition': 'attachment; filename="cobbled-paths.hpgl"' }) - return r if __name__ == '__main__': diff --git a/requirements.txt b/requirements.txt index b51679cf98806e102b8c12cbc24dde100809f3a5..0021545742166a0cda9256e87f6c634a25919d33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Flask -pyinkscape \ No newline at end of file +pyinkscape +requests \ No newline at end of file diff --git a/svg_to_hpgl.py b/svg_to_hpgl.py index f025451bc52789f0c072ee3cb8c2d704cc6e2885..ec72affb42bd8002e6b5732a92eead7034499799 100644 --- a/svg_to_hpgl.py +++ b/svg_to_hpgl.py @@ -1,5 +1,4 @@ from hpgl_multipen_output import HpglMultipenOutput -from sys import argv def svgToHPGL (path, speed=1, penCount=8, force=2): e = HpglMultipenOutput()