Packing History in a Zip File

Day 94 of 100 Days Coding Challenge: Python

Today I leveled up my app by teaching it how to bundle everything into one neat little care package: CSV, PNG, quizzes, and all—zipped up and ready to go. Think of it as a take-home kit for history nerds. Instead of juggling screenshots and exports, now you can grab one file, open it later, and relive the glory of your filters and quizzes.

What excites me most is not just the feature itself but the possibilities it unlocks. I suddenly realized this kind of import/export bundle could be handy for any project where you want to ship outputs to others—or just yourself. If I had to re-create the logic from scratch, I’d probably be lost in the weeds. But now? I know the function exists, I know how to call it, and I have the code. That’s enough to carry the trick into future projects. And yes, I’m ridiculously happy about that.

Today’s Motivation / Challenge

Why does this matter? Because nobody wants to lose work. Whether it’s a report, a chart, or a quiz, being able to package and save everything guarantees you can come back to it later. Plus, if you’re sharing your app with others, a zipped curriculum pack makes you look like you thought ahead. It’s like sending someone leftovers in a perfectly labeled container instead of handing them a messy plate.

Purpose of the Code (Object)

The code bundles your selected civilizations, filters, quizzes, and images into a single zip file. Inside, you’ll find JSON, CSV, PNGs, and even a README so you know what’s what. It’s designed to be portable, so you can save a snapshot of your exploration, share it with a friend, or use it as a reference for another project.

AI Prompt

Add the following function:
Curriculum packs

  • Bundle lens + selected civs + quiz + images into a zip.
  • ✅ Accept: zip contains JSON, CSV, PNGs, README.

Functions & Features

  • Collect current filters, data, and quiz results.
  • Export charts and timelines as PNGs.
  • Save everything into a single zip archive.
  • Include a README file for clarity.

Requirements / Setup

You’ll need:

  • Python 3.11

Installs:

pip install plotly kaleido streamlit

Minimal Code Sample

import zipfile, io

with zipfile.ZipFile(“curriculum_pack.zip”, “w”) as zf:

    zf.writestr(“filters.json”, json.dumps(filters))

    zf.writestr(“data.csv”, df.to_csv(index=False))

    zf.writestr(“README.txt”, “Curriculum pack export”)

Writes JSON, CSV, and a README into a zip file in memory or on disk.

The Civilization Timeline Builder

Notes / Lessons Learned

Sometimes it’s the little discoveries that bring the most joy. I used to write imports like:

import io

import csv

But today I learned you can just write:

import io, csv

It’s small, but it makes me smile—one of those tiny conveniences you only stumble upon while coding.

The helper function itself starts by converting Plotly figures into PNG bytes (thanks to Kaleido, which I’d already added earlier). Then, with the io library, I created in-memory streams for text and files. io.StringIO in particular is handy: it treats strings like files, making them easy to read and write. I’d used it before for downloads, but seeing it in action again for zipping files reminded me just how versatile it is.

The result: a neat little archive of history in my downloads folder. Simple, but powerful.

Optional Ideas for Expansion

  • Add an “unzip and load” feature so packs can be re-imported into the app.
  • Include a summary.txt file with auto-generated narrative recaps.
  • Allow multiple packs to be batched into one archive for classroom use.

Leave a Reply

Your email address will not be published. Required fields are marked *