Skip to content
Snippets Groups Projects
Commit b6905ce5 authored by Holger Karl's avatar Holger Karl
Browse files
parents 429c5563 4c0d4c8f
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
all: survey.lss
%.lss: %.yaml survey.j2
./yaml2lss.py "$<" > "$@"
./yaml2lss.py "$<" -o "$@"
clean:
rm -f survey.lss
......@@ -172,15 +172,20 @@
</fields>
<rows>
{%- for question in questions %}{% set question_loop = loop %}
<row>
<qid><![CDATA[{{ 3*question_loop.index }}]]></qid>
<attribute><![CDATA[statistics_showgraph]]></attribute>
<value><![CDATA[1]]></value>
</row>
<row>
<qid><![CDATA[{{ 3*question_loop.index + 1 }}]]></qid>
<attribute><![CDATA[statistics_showgraph]]></attribute>
<value><![CDATA[0]]></value>
<value><![CDATA[1]]></value>
</row>
<row>
<qid><![CDATA[{{ 3*question_loop.index + 2 }}]]></qid>
<attribute><![CDATA[statistics_showgraph]]></attribute>
<value><![CDATA[0]]></value>
<value><![CDATA[1]]></value>
</row>
{%- endfor %}
</rows>
......
......@@ -21,15 +21,23 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
import argparse
import base64
import jinja2
import mimetypes
import os.path
import sys
import yaml
survey = None
with open(sys.argv[1]) as file:
survey = yaml.full_load(file)
parser = argparse.ArgumentParser()
parser.add_argument("--output", "-o", metavar='FILE', type=argparse.FileType('w'), dest='output', help="write output to file FILE (use `-` for stdout); default: -", default='-')
parser.add_argument(metavar='FILE', type=argparse.FileType('r'), dest='input', help="read input from file FILE (use `-` for stdin)")
args = parser.parse_args()
survey = yaml.full_load(args.input)
fpath = os.path.dirname(args.input.name)
for question in survey['questions']:
# trim question "title" to 19 characters (max len is 20 and we need the first character ourselves)
......@@ -38,6 +46,7 @@ for question in survey['questions']:
# create data url for image, if specified
if 'image' in question:
fname = question['image']
fname = os.path.join(fpath, fname)
mimetype = mimetypes.guess_type(fname)[0]
contents = None
with open(fname, 'rb') as file:
......@@ -53,5 +62,5 @@ with open(r'survey.j2') as file:
template = jinja2.Template(file.read())
s = template.render(survey)
sys.stdout.write(s)
args.output.write(s)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment