# ModernLib ZIP with RTF-disguised `.doc` — daily extraction pattern

Use when a user uploads a ModernLib/Russian ebook ZIP whose inner filename is mojibake and whose `.doc` is actually RTF.

## Recognition

```bash
python3 - <<'PY'
import zipfile, pathlib
p = pathlib.Path('/path/to/book.zip')
with zipfile.ZipFile(p) as z:
    for info in z.infolist():
        print(info.filename, info.file_size)
PY
file /stable/project/source/book.doc
```

Typical result:

- ZIP contains a `.url` and a `.doc` with garbled filename;
- `file book.doc` reports: `Rich Text Format data, version 1, ANSI, code page 1251`.

## Stable storage layout

```bash
proj=/home/spazio/<book_project>
mkdir -p "$proj/source" "$proj/text" "$proj/daily_fragments" "$proj/daily_outputs"
```

Copy the original ZIP into `source/original_modernlib.zip`, then extract/rename the RTF-ish `.doc` to `source/book.doc` instead of preserving the mojibake filename.

## RTF extraction approach

Decode bytes as cp1251 and strip RTF control words. Preserve paragraph breaks and common typography controls.

Important RTF details:

- handle hex escapes like `\\'cf` as cp1251 bytes;
- ignore destinations such as `fonttbl`, `stylesheet`, `info`, `pict`, `object`, headers/footers;
- convert `\par` / `\line` to newlines;
- support `\uN` unicode escapes with `\ucN` skip count;
- normalize repeated blank lines after extraction.

Verify by printing:

- character count;
- line count;
- first 2–3 KB of readable Russian text;
- table of contents / chapter headings.

## Chunking

Split by headings such as:

```regex
^(Благодарности|От издателя|Предисловие(?: ко второму изданию)?|Введение|Глава\s+\d+[^\n]*)$
```

Then split oversized sections by paragraphs into ~12k–18k character fragments, preserving heading titles in `manifest.json`.

## Scheduling pitfall

Before creating the cron job, confirm the user's intended timezone. If the scheduler uses UTC and the user means Bali/Samui (UTC+7), daily `14:30` local is cron `30 7 * * *`.

## Copyright

For daily outputs, produce transformative synthesis: theory, tools, questions, practices, Cosmos Luminosity applications, and short original formulations. Do not reproduce long copyrighted passages from the book.
