Added pad downloading.

This commit is contained in:
Gijs 2024-03-26 23:57:12 +01:00
parent e5ef47b28d
commit e8c36e10d7
3 changed files with 20 additions and 10 deletions

26
app.py
View File

@ -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__':

View File

@ -1,2 +1,3 @@
Flask
pyinkscape
pyinkscape
requests

View File

@ -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()