──────────────────────────────────────

52. Prepare Reports to Share · Build a Weekly Club Report Bundle

Generate a readable HTML report from a batch of updates, verify the archive and prepare a draft with the archive attached.

Lesson files · lessons/share-reports/weekly-club-report-bundle

Before you start
- Escape text before inserting it in HTML.
- Reopen an in-memory ZIP and read a named member.
- Attach a file to an offline email draft.

By the end
- Create an escaped HTML report and text summary in one ZIP, including for a week with zero updates.
- Attach the ZIP to a draft and confirm the member names, summary and attachment filename.

Where you can use it
Prepare an offline draft with one ZIP that gives a reviewer both a browser report and a plain-text summary.

A club organiser keeps weekly notes from several clubs. Collect all the updates before creating the report. Use an h1 for the report title and an h2 for each club, followed by its note. The starter gives you a document with a language, a UTF-8 declaration and a main landmark. Add escaped headings and notes to that template. Make a ZIP that contains the document and a text summary, then attach the ZIP bytes to an EmailMessage. Open the ZIP you built and read the summary back to check it before sharing.

Predict
What order do the updates appear in?
- Alphabetical order by club name.
- The same order as the input list.

Worked example (example.py)

updates = [("Chess", "Held a tournament."), ("Choir", "Learnt a new song.")]
lines = [f"{club} - {note}" for club, note in updates]
print("\n".join(lines))


Example result
Chess - Held a tournament.
Choir - Learnt a new song.

Prepare one bundle for the club organiser. Read a week label, a non-negative update count, then two lines per update with the club name first and its note second. Build report.html with Club report for followed by the week in an h1. Give each update an h2 and a paragraph in input order. Escape the week, names and notes as HTML text. Put report.html and summary.txt in that order in a ZIP. In summary.txt write Updates: and the count, then one line per update in the form Club - note. Make an email with subject Club report, fictional .invalid addresses and the ZIP attached as club-report.zip. For the check, print the h1 from the report, the ZIP filenames separated by a comma and space, the summary read back from the ZIP and Attachment: followed by the draft’s attachment filename. A zero count still produces a report and a summary.

Starter program (starter.py)

week = input()
count = int(input())
updates = []
for _ in range(count):
    updates.append((input(), input()))

report_start = """<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Club report</title>
</head>
<body>
<main>"""
report_end = "</main>\n</body>\n</html>"

# Add escaped headings and notes, then create and inspect the bundle.
print(f"Preparing {count} updates for {week}")


Starter input
Week 4
2
Robotics & Design
Tested the rover.
Garden Club
Planted 12 seedlings.

Hint
Start with the lines in the report template. Collect a summary list alongside it. When the report and summary are ready, build the ZIP, create the draft and inspect what you created.

Case 1. Try the sample
Input
Week 4
2
Robotics & Design
Tested the rover.
Garden Club
Planted 12 seedlings.
Expected output
<h1>Club report for Week 4</h1>
report.html, summary.txt
Updates: 2
Robotics & Design - Tested the rover.
Garden Club - Planted 12 seedlings.
Attachment: club-report.zip

Case 2. Week with no updates
Input
Week 5
0
Expected output
<h1>Club report for Week 5</h1>
report.html, summary.txt
Updates: 0
Attachment: club-report.zip

Case 3. Preserve text characters
Input
Arts & Science
1
Café <Lab>
Reached > 20 visitors.
Expected output
<h1>Club report for Arts &amp; Science</h1>
report.html, summary.txt
Updates: 1
Café <Lab> - Reached > 20 visitors.
Attachment: club-report.zip

Project checklist
Run the sample case.

Project checklist
Try one different case and explain what happened.

Marking criterion
Program behaviour (4 points)
Each required behaviour works on the supplied cases.

Marking criterion
Use of the lesson concept (3 points)
The code uses the main idea in a clear, purposeful way.

Marking criterion
Test evidence (2 points)
The reflection describes a case, its expected result and what happened.

Marking criterion
Explanation (1 points)
The learner explains a change or design decision in their own words.

Stretch
On a local computer, save your source as main.py in a practice folder and run python3 main.py or py main.py on Windows. Enter the sample lines one at a time. To keep the outputs, add with open("club-report.zip", "xb") as file: and write bundle_bytes inside it with file.write(bundle_bytes). Use another block with club-report.eml and draft.as_bytes(). The x protects an existing file. Open report.html from the ZIP to inspect the headings and notes. You can use your browser’s Print to PDF feature if someone needs a PDF copy.

Reflect
What could you check in the saved bundle before asking the club organiser to review the draft?

Check your prediction
The same order as the input list. The loop keeps the list order. join() puts a newline between the resulting lines.
