# ``year`` is the current year: datetime.datetime.now().year # ``talks`` is a list of processed form entries from jinja2 import Template, Environment, select_autoescape, pass_eval_context from markupsafe import Markup, escape from IPython.core.display import HTML import re env = Environment(autoescape=select_autoescape(['html', 'xml'])) _paragraph_re = re.compile(r'(?:\r\n|\r(?!\n)|\n){2,}') @pass_eval_context def nl2br(eval_ctx, value): result = u'\n\n'.join(u'

%s

' % p.replace('\n', Markup('
\n')) for p in _paragraph_re.split(jinja2.filters.escape(value))) result = re.sub(r'(https?[/\-.:a-zA-Z0-9_]+)',r'\1',result) if eval_ctx.autoescape: result = Markup(result) return result env.filters['br'] = nl2br template = env.from_string(""" EAMS {{year}} talk submissions

EAMS {{year}} talk submissions

{% for talk in talks %}

{{talk.title|br}}

{{talk.names|br}}

{{talk.email}}

{{talk.format}}

{{talk.timezone}}

{{talk.description|br}}

{% if talk.notes %}

Notes: {{talk.notes|br}}

{% endif %}
{% endfor %} """) h = template.render(year=year, talks=sorted(talks,key=lambda t: re.sub(r'\W','',t['title'].lower()))) with open('talks.html','w') as f: f.write(h)