Metadata-Version: 2.4
Name: schedz
Version: 0.1.0
Summary: Read training sessions from a Google Calendar.
Author: m09
Author-email: m09 <142691+m09@users.noreply.github.com>
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Dist: platformdirs>=4
Requires-Dist: pydantic>=2.13
Requires-Dist: pyyaml>=6
Requires-Dist: google-api-python-client>=2 ; extra == 'google'
Requires-Dist: google-auth-oauthlib>=1 ; extra == 'google'
Requires-Python: >=3.13
Provides-Extra: google
Description-Content-Type: text/markdown

# `schedz`

Read training sessions from a Google Calendar, read-only. Shared by
[invoicez](https://github.com/shuuchuu/invoicez), which bills them, and
[deckz](https://github.com/shuuchuu/deckz), which tells which deck is taught
next.

## Installation

    pip install "schedz[google]"

Without the `google` extra, schedz still parses events read from a JSON file
(`read_events_file`), e.g. an anonymised test fixture.

## Setup

In Google Cloud, enable the Google Calendar API and create an OAuth client of
type *Desktop app*. Save its JSON as `client-secrets.json` in schedz's user
config directory (`~/.config/schedz/` on Linux). The first call opens a browser
for consent; the token is cached next to it (`token.json`), readable by you
only, and serves every tool using schedz.

## Settings

A tool reads its calendar settings into `CalendarSettings`, or a subclass
adding its own keys (invoicez's `gcal` section is one):

```yaml
calendar_id: someone@example.com
# Verbose regex: groups continuation, company, training, place, and optionally
# extra and tentative. Titles are matched whole.
title_pattern: |
  \s*
  (?P<tentative> \? \s+ )?
  (?P<continuation> -> \s+ )?
  (?P<company> .*? ) \s+ - \s+
  (?P<training> .*? ) \s+ - \s+
  (?P<place> .*? )
  (?: \s+ - \s+ (?P<extra> .*? ) )?
  \s*
# Optional: what a timed event counts as, in hours.
durations: {half_day_hours: [2.5, 4], day_hours: [6, 9]}
```

## Calendar conventions

- A title such as `Orsys - BDA - CV - Intra Acme` is a session: company,
  training, place and extra, kept in their case.
- `-> Orsys - BDA - CV - Intra Acme` continues the latest earlier session with
  the same title (ignoring case): together they make one engagement.
- `? Orsys - BDA - CV` is an unconfirmed booking (`tentative`).
- All-day events count their days; timed events of 2.5 to 4 hours are
  half-days, of 6 to 9 hours days; others are reported, not kept.
- The description may hold YAML: `ref` (the client's reference),
  `preparation_days`, `trainees` (the number of people trained) and `invoice`
  (a number billed by hand). HTML and free text are reported and ignored.

Problems are reported as `Diagnostic`s (`info`, `warning`, `error`), never
raised.

## Use

```python
from schedz.loading import fetch_calendar, read_engagements
from schedz.settings import CalendarSettings

settings = CalendarSettings.model_validate(mapping)
engagements, diagnostics = read_engagements(
    fetch_calendar(settings.calendar_id), settings
)
```

`schedz.google` lists the calendars (`list_calendars`) and fetches events
(`fetch_events`); `schedz.parsing` and `schedz.grouping` turn them into
`Session`s and `Engagement`s.

## Development

- `uv sync`, then `uv run doit install_hooks`: every commit runs `doit check
  test` (ruff, pyrefly, pytest) through prek. There is no CI.
- `tests/assets/events.json` is invoicez's anonymised fixture (its
  `scripts/dump_gcal_fixture.py`).

## Releasing

1. `uv run bumpver update --minor` (or `--patch`): bumps, commits, tags and
   pushes.
2. `uv run doit publish`: builds and uploads to PyPI with the token of
   `creds.env`, a gitignored file at the repository's root holding one line,
   `export UV_PUBLISH_TOKEN=pypi-...`, readable by you only (`chmod 400`).
