Coverage for e2xgrader/exchange/utils.py: 100%
10 statements
« prev ^ index » next coverage.py v7.4.2, created at 2024-03-14 13:22 +0100
« prev ^ index » next coverage.py v7.4.2, created at 2024-03-14 13:22 +0100
1from textwrap import dedent
3import nbformat
4from nbconvert.exporters import HTMLExporter
7def generate_student_info_file(
8 filename: str, username: str, hashcode: str, timestamp: str
9) -> None:
10 """
11 Generate a student info file with the given username, hashcode, and timestamp.
13 Args:
14 filename (str): The name of the file to be generated.
15 username (str): The username of the student.
16 hashcode (str): The hashcode associated with the student.
17 timestamp (str): The timestamp of when the file is generated.
19 Returns:
20 None
21 """
22 with open(filename, "w") as f:
23 f.write(
24 dedent(
25 f"""
26 Username: {username}
27 Hashcode: {hashcode}
28 Timestamp: {timestamp}
29 """
30 )
31 )
34def generate_submission_html(
35 notebook_file: str,
36 html_file: str,
37 hashcode: str,
38 timestamp: str,
39 exporter: HTMLExporter,
40) -> None:
41 """
42 Generate a submission HTML file from the given notebook file.
43 This includes the hashcode and timestamp.
45 Args:
46 notebook_file (str): The path to the notebook file.
47 html_file (str): The path to save the generated HTML file.
48 hashcode (str): The hashcode to include in the generated HTML file.
49 timestamp (str): The timestamp to include in the generated HTML file.
50 exporter (HTMLExporter): The exporter to use for generating the HTML file.
52 Returns:
53 None
54 """
55 html, _ = exporter.from_notebook_node(
56 nbformat.read(notebook_file, as_version=nbformat.NO_CONVERT),
57 resources={"hashcode": hashcode, "timestamp": timestamp},
58 )
59 with open(html_file, "w") as f:
60 f.write(html)