Skip to content
jsem-nerad edited this page Nov 23, 2026 · 6 revisions

Command Line

Installing the package gives you a strava-cz command that does everything the library does. It prints a readable table by default and machine-readable JSON on request, so the same command serves a terminal and a cron job.

pip install "strava-cz[cli]"

The [cli] extra pulls in keyring, so passwords can go to the operating system's credential store, and cryptography, so that on a machine without one they can be encrypted into the profile file instead. The command itself works without either — see Profiles — and needs nothing beyond the standard library.

python -m strava_cz does the same thing, for when the script directory is not on PATH.

The command also has one subcommand that is not for people: strava-cz mcp serves the same things to an AI agent over MCP, and needs pip install "strava-cz[mcp]". It is described in MCP Server.

First run

strava-cz profile add skola --username your.username --canteen 3753 --verify
strava-cz menu --week

--verify logs in once to check the credentials before storing them, so a typo is caught now rather than the next morning. The password goes to the OS keyring, or, on a machine that has none, is encrypted into the profile file under a passphrase you choose — the command says which, and --secret lets you insist. See Profiles.

Without a profile you can pass the credentials directly, with the password coming from $STRAVA_CZ_PASSWORD or a prompt:

strava-cz --username your.username --canteen 3753 menu

Commands

command what it does
menu show the published menu, day by day
ordered list what is ordered right now, with the total
order ID... order meals, in one transaction
cancel ID... cancel orders, in one transaction
balance print the balance and nothing else
account who is logged in, at which canteen
raw dump the untouched API response, for a bug report
profile ... manage stored logins — see Profiles

A meal id is the day and the slot, such as 2026-09-21:O1, and it means the same thing in every run. A bare number is refused with exit code 2: the canteen's own number for a meal (the API's veta) changes at every login and every run is a new login, so an old number can be another meal on another day. If the canteen republishes a slot, the id stays and the dish changes, so --dry-run shows the name. This is new in 0.5.0; 0.4.0 still takes numbers. See the Changelog.

Reading the menu

Mon 21.09.2026
  ·  2026-09-21:PO  Polévka    Zeleninová    this item cannot be ordered separa…
  ○  2026-09-21:O1  Oběd 1     Bramborové knedlíky s kuřecím masem a špe…  50 Kč
  ✓  2026-09-21:O2  Oběd 2     Bramborové špalíky sypané cibulkou, kysan…  50 Kč

Fri 25.09.2026  not ordered automatically
  ○  2026-09-25:O1  Oběd 1     Kuřecí asijská pánev, kari rýže, tvaroháč…  50 Kč

2 days · 4 meals · 3 orderable · 1 ordered · balance 0.00 Kč
mark meaning
✓ ordered
○ can be ordered right now
· cannot; the reason is printed after the name

A day header says no school when the canteen does not cook, and not ordered automatically for a day the canteen's standing order skips. That second one is not a restriction: those meals can be ordered by hand like any other, they just never appear on their own. See Meals and Restrictions.

Filtering

Every filter maps onto a Menu.get_days() keyword, and they combine.

strava-cz menu --today
strava-cz menu --week --orderable
strava-cz menu --from 2026-09-07 --to 2026-09-11 --type main
strava-cz menu --no-auto-ordered          # the days you must order yourself
strava-cz menu --ordered                  # what is already ordered
strava-cz menu --include-no-school        # holidays too
strava-cz menu --allergens                # list allergens under each meal
flag effect
--from / --to date range, inclusive; takes YYYY-MM-DD, today, tomorrow, yesterday
--today / --tomorrow / --week / --next-week shorthand for a range
--type soup|main|unknown keep one kind of meal; repeatable
--orderable / --not-orderable can it be ordered right now
--ordered / --not-ordered is it already ordered
--auto-ordered / --no-auto-ordered whole days the canteen does or does not order for you
--include-no-school also show days with no cooking
--allergens print each meal's allergens

Leaving a filter out means "do not filter". --not-orderable is not the same as omitting --orderable: the first keeps only the meals you cannot order, the second keeps everything.

Ordering

strava-cz order 2026-09-21:O1 2026-09-22:O1   # order two meals
strava-cz order 2026-09-21:O1 --dry-run       # say what would happen, send nothing
strava-cz cancel 2026-09-21:O1
strava-cz order 2026-09-21:O1 2026-09-22:O1 --continue-on-error
strava-cz order 2026-09-21:O1 2026-09-21:O2 --strict-duplicates

Both commands run as one transaction: every meal is staged, the changes are saved together, and the result is read back from the canteen's records. If a step fails before the save, the staged changes are rolled back and nothing is saved. If the save's answer is lost, the command reads back what happened. If there is nothing to change, no request is sent at all.

Exit code 1 from a write doesn't always mean nothing happened. When the canteen accepted the save but it can't be confirmed, the message says so and --json names the meals in error.unconfirmed and error.changed. Check with strava-cz ordered before retrying.

  • --dry-run resolves the ids and prints what would change — including meals that are already in the wanted state and two meals competing for the same slot — without sending a single write. It is the safe way to check a script before letting it run. With --json, meals carries the full record of each meal it would order, name included. It answers for the flags you give it: without --continue-on-error one refusal stops the whole batch, so would_change is then empty and the meals held back are in blocked, with the same exit code as the real call. What it can't know is the account's limit: if the balance would go below zero it warns and gives balance_after, because the canteen may refuse with exit code 5, but it still exits 0.
  • --continue-on-error orders what can be ordered and reports the rest, instead of rolling everything back at the first failure.
  • --strict-duplicates fails when two chosen meals compete for the same slot (same day, same kind). By default the first one wins and the rest are skipped with a warning.
$ strava-cz order 2026-09-25:O1 2026-09-25:O2 2026-09-21:PO 2026-09-21:O2 2030-01-01:O1 --dry-run --continue-on-error
dry run - nothing was sent to the canteen

would order:
  2026-09-25:O1  Fri  Oběd 1     Kuřecí asijská pánev, kari rýže, tvaroh…  50 Kč
  balance change: -50 Kč
  2026-09-21:O2: already ordered, nothing would be sent
  2026-09-25:O2: same slot as 2026-09-25:O1, would be skipped
  2026-09-21:PO: this item cannot be ordered separately
  2030-01-01:O1: not in the fetched menu

JSON output, for scripts

--format json (or --json) writes one object to stdout. Every warning, prompt and diagnostic goes to stderr instead, so the stream stays parseable even when something goes wrong.

strava-cz --json menu --orderable | jq '.days[].meals[] | select(.type=="main") | .id'
strava-cz --json ordered | jq '.total_price'
strava-cz --json balance | jq -r '.balance'

Success carries "ok": true and the command's data:

{
  "ok": true,
  "command": "menu",
  "days": [
    {
      "date": "2026-09-25",
      "weekday": "friday",
      "status": "not_auto_ordered",
      "day_code": "T",
      "no_school": false,
      "auto_ordered": false,
      "ordered": false,
      "meals": [
        {
          "id": "2026-09-25:O1",
          "date": "2026-09-25",
          "type": "main",
          "variant": "Oběd 1",
          "name": "Kuřecí asijská pánev, kari rýže, tvaroháček",
          "price": 50.0,
          "ordered": false,
          "can_order": true,
          "can_cancel": true,
          "order_restriction": "none",
          "cancel_restriction": "none",
          "allergens": [{"code": "01", "name": "Obiloviny obsahující lepek"}],
          "deadline": "2026-09-24T15:00:00",
          "currency": "Kč"
        }
      ]
    }
  ],
  "account": {"username": "...", "balance": 0.0, "currency": "Kč", "...": "..."}
}

Failure carries "ok": false and an error you can branch on without reading prose:

{
  "ok": false,
  "command": "order",
  "error": {
    "type": "MealNotOrderableError",
    "message": "Cannot order meal 2026-09-21:PO: this item cannot be ordered separately",
    "meal_id": "2026-09-21:PO",
    "reason": "unavailable"
  }
}

The keys mirror the library's own attribute names, with one exception: id is the library's Meal.key, because a script passes it back to a later run. Enums appear as their lower-case names ("closed", "unavailable", "not_auto_ordered") rather than the canteen's raw letters. The session id and the password never appear in any payload.

Exit codes

code meaning
0 success
1 the canteen or the network failed
2 wrong usage
3 login rejected
4 a meal could not be ordered or cancelled, or was not found
5 not enough money on the account
6 a profile or keyring problem

With --continue-on-error the code still tells you the worst of what happened: 5 if any meal was refused for money, otherwise 1 if the canteen or the network failed on any of them, otherwise 4 if only some meals were refused or not found. A session that ended stops the batch with 3 and nothing saved.

strava-cz --json order 2026-09-21:O1 > result.json
case $? in
    0) ;;
    5) echo "top up the account" ;;
    4) echo "that meal is not available" ;;
    *) echo "something else went wrong" ;;
esac

Colour

Colour is emitted only when stdout is a terminal. A pipe, a redirect, a cron job, a TERM=dumb session or a set NO_COLOR variable all get plain text. --color always forces it on, --color never off.

Global options

option effect
-p, --profile NAME which stored profile to use
--profile-store PATH use a different profile file
--username + --canteen log in without a profile
--language LANG language the canteen answers in
--timeout SEC request timeout (default 15)
--format, --json output format
--color auto, always or never
-V, --version print the version

Running it from cron

Cron has no terminal, so the password must come from somewhere that does not ask. Either store it in the keyring on a machine that has one, or point the profile at an environment variable:

15 7 * * 1-5  STRAVA_CZ_PASSWORD_SKOLA=... /usr/local/bin/strava-cz --json --profile skola ordered >> ~/lunch.log 2>&1

$STRAVA_CZ_PASSWORD_<PROFILE> beats $STRAVA_CZ_PASSWORD, which beats whatever the profile has stored — so one job can drive several accounts without editing any profile.

For an encrypted profile, set $STRAVA_CZ_PASSPHRASE_<PROFILE> (or $STRAVA_CZ_PASSPHRASE) instead and let the stored password stay encrypted on disk:

15 7 * * 1-5  STRAVA_CZ_PASSPHRASE_SKOLA=... /usr/local/bin/strava-cz --json -p skola ordered >> ~/lunch.log 2>&1

Clone this wiki locally