Boss

Boss: Expedition Toolkit

The boss
Boss Fight!
Every passing test breaks a shield.

The Guild's explorers keep a logbook of creature sightings. Each line looks like date | island | creature. The Expedition Master wants a command-line tool that turns the logbook into a report. Time to use your whole toolbox!

Assignment

  1. build_parser() returns an ArgumentParser(prog="expedition") with three arguments:
    • a positional logbook (the file path),
    • --top: an int, default 2,
    • --since: default None. Use type=date.fromisoformat, so argparse turns the text into a date.
  2. read_logbook(path) reads the file with pathlib. It returns a list of Sighting(day, island, creature) namedtuples.
    • day is a date. Strip spaces from every part.
    • Skip blank lines.
    • If any other line doesn't parse, call log.warning("Skipping line %d: %r", number, line) and keep going. Line numbers start at 1.
  3. main(argv) parses argv and reads the logbook. If --since was given, it keeps only sightings on or after that day. Then it returns this report, with the lines joined by "\n":
Sightings: 6
Span: 2026-04-01 to 2026-04-04 (4 days)
Top: whale x3, gull x2
Busiest island: Amber Isle
  • "Span" counts both the first and the last day.
  • "Top" shows the --top most common creatures. Use a Counter.
  • If no sightings are left, return "No sightings" instead.