-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport_generator.py
More file actions
26 lines (20 loc) · 822 Bytes
/
report_generator.py
File metadata and controls
26 lines (20 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Standard imports
import codecs
# Third-party imports
from jinja2 import Environment, FileSystemLoader
# Module functions
def create_report(article_responses, base_url):
"""
Generates a HTML response for the application run result.
Args:
article_responses: A list of ArticleResponse objects to be included in
the report.
base_url: Base Wikipedia URL to generate links to original articles.
"""
env = Environment(loader=FileSystemLoader('templates'), autoescape=True)
template = env.get_template('template.html')
output_from_parsed_template = template.render(
articles=article_responses, base_url=base_url)
# to save the results
with codecs.open("report.html", "wb", 'utf-8') as fh:
fh.write(output_from_parsed_template)