Skip to content

Quick Start

jsem-nerad edited this page Sep 1, 2026 · 3 revisions

Quick Start

Everything you need to order lunch from Python.

Log in

from strava_cz import StravaCZ

strava = StravaCZ("your.username", "YourPassword123", "3753")
print(strava.user)
Vojtěch Nerad (your.username)
  Email:   you@example.com
  Balance: 512.50 Kč
  Canteen: Školní jídelna, Praha 5 - Smíchov

Better still, use it as a context manager — it logs out and closes the connection pool for you, even if something raises:

with StravaCZ("your.username", "YourPassword123", "3753") as strava:
    ...

Better again, keep the credentials out of the source entirely. Store them once — strava-cz profile add skola --username your.username --canteen 3753 — and then:

with StravaCZ.from_profile("skola") as strava:
    ...

The password goes to the operating system's keyring, not into any file this library writes. See Profiles.

Fetch the menu

Nothing is loaded until you ask for it:

strava.menu.fetch()
strava.menu.print()
Thu 03.09.2026
  [-]   86 Polévka      Bramborová                                   (0 Kč)  - this item cannot be ordered separately
  [ ]    5 Oběd 1       Kuřecí kostky na paprice, těstoviny, čaj     (50 Kč)
  [ ]    6 Oběd 2       Zapečené těstoviny se šunkou, salát          (50 Kč)

The marks are [x] ordered, [ ] orderable, [-] blocked — with the reason spelled out.

Look around

from strava_cz import MealType

# Everything, grouped by day or flat
days = strava.menu.get_days()
meals = strava.menu.get_meals()

# Only what you can actually order right now
orderable = strava.menu.get_meals(orderable=True)

# Only main dishes, only this week
lunches = strava.menu.get_meals(
    meal_types=[MealType.MAIN],
    orderable=True,
    date_from="2026-09-07",
    date_to="2026-09-11",
)

for meal in lunches:
    print(f"{meal.date}  [{meal.id}]  {meal.name}  {meal.price} Kč")

Menu behaves like a sequence of days:

print(len(strava.menu))          # number of days with meals
print(strava.menu[0].date)       # first day

for day in strava.menu:
    print(day.date, len(day.meals))

Order

result = strava.menu.order_meals(5, 9)
print(result)          # "2 changed"
print(result.changed)  # (5, 9)

The library stages both meals, saves once, then re-fetches the menu to confirm the canteen really recorded them. If anything fails, the staged changes are discarded and nothing is saved.

Cancel

strava.menu.cancel_meals(5, 9)

Handle the obvious failures

from strava_cz import InsufficientBalanceError, MealNotOrderableError

try:
    strava.menu.order_meals(5)
except MealNotOrderableError as exc:
    print(f"Cannot order this: {exc.reason.description}")
except InsufficientBalanceError:
    print(f"Only {strava.user.balance} Kč left")

Put together

import os
from strava_cz import MealType, StravaCZ

with StravaCZ(
    os.environ["STRAVA_USERNAME"],
    os.environ["STRAVA_PASSWORD"],
    os.environ["STRAVA_CANTEEN"],
) as strava:
    strava.menu.fetch()

    # Order the first available "Oběd 1" on every day that has nothing ordered yet
    for day in strava.menu.get_days():
        if day.ordered:
            continue
        choice = next(
            (m for m in day.orderable if m.type is MealType.MAIN and m.variant == "Oběd 1"),
            None,
        )
        if choice:
            strava.menu.order_meals(choice.id)
            print(f"Ordered {choice.name} for {choice.date}")

Where next

A note on meal ids. A meal's id is the API's veta field. It identifies a meal within the currently published menu only, and changes whenever the canteen republishes it. Always take ids from a fresh menu.fetch(), never from a hard-coded list.

Without writing any Python

Everything above is also a command. See Command Line.

strava-cz menu --week --orderable
strava-cz order 37 --dry-run
strava-cz order 37
strava-cz --json ordered | jq '.total_price'

Clone this wiki locally