← Course Home
Module 13 · Tier 7

Stale-Login Reporter, CLI-Style

"Flag every account inactive 90+ days" — a standard offboarding/compliance check. Ten labs on Module 9 — argparse, datetime, env vars — over the real fixture's login timestamps.

Lab 1

The --days Flag

Build a parser with --days (type int, default 90). Parse ["--days", "60"]. Print args.days.

60
Lab 2

The Default

Using the same parser, parse an empty list [] (no flag given). Print args.days.

90
Lab 3

Parse a Real Login Timestamp

Parse USERS[0]'s (Julio) lastLogin with datetime.fromisoformat(). Print the result.

2026-07-24 09:14:00+00:00
Lab 4

Days Since Login

Using a fixed reference of datetime.fromisoformat("2026-07-26T00:00:00+00:00"), compute how many days ago Julio logged in. Print .days.

1
Lab 5

Guard the None Case

Write days_since(user) that returns None if lastLogin is None, otherwise the day count from Lab 4's math. Call it on USERS[3] (Dana), then USERS[0] (Julio).

None then 1
Lab 6

Report Every Real Login

Loop all USERS, using days_since(), skipping Dana (whose result is None). Print "FIRSTNAME: N days" for the other 11.

→ 11 lines
Lab 7

Filter By Threshold

Build a list of first names of every user where days_since(u) is not None and greater than 90. Print the list.

['Bina', 'Tri', 'Rosa', 'Pat']
Lab 8

The Unused Token

Print os.environ.get("AUDIT_TOKEN", "not set") — this variable isn't set on your system, and this script never actually calls a real API, but reading a token this way is the correct habit either way.

not set
Lab 9

A Reusable Threshold Function

Write stale_accounts(users, days) combining Labs 5 and 7 — returns a list of first names inactive longer than days. Call it with 90, then with 30.

['Bina', 'Tri', 'Rosa', 'Pat'] then ['Bina', 'Tri', 'Layla', 'Rosa', 'Yuki', 'Pat']
Lab 10 · Capstone

The Full CLI Report

Parse --days (default 90) with a hardcoded arg list ["--days", "90"]. Call stale_accounts() with the parsed threshold. Print "Stale accounts (inactive N+ days): COUNT", then every name on its own line.


Stale accounts (inactive 90+ days): 4
Bina
Tri
Rosa
Pat
Now go practice

Open problems/tier07_stale_login_reporter.py and do all 10 problems locally. Uses fixture.py -- type it in first from DAY1_01_FIXTURE.md if it's not already in this folder. Run python check.py in problems/ to grade everything.

Tier 7 complete

On to Tier 8

the --days flag → the default → parsing a real timestamp → days since login → guarding None → reporting every real login → filtering by threshold → the unused token → a reusable threshold function → the full CLI report.

← Back to Module 13