# Changelog of Marjane Mall Scraper – Morocco Prices, Stock & Discounts (`badr_xba/marjane-mall-scraper`) Actor

- **URL**: https://apify.com/badr_xba/marjane-mall-scraper/changelog.md
- **Full Actor documentation**: https://apify.com/badr_xba/marjane-mall-scraper.md

## Changelog

### 2026-11-27 (retry rule)

- Owner rule: a refusal by Marjane Mall (403, 429, anti-robot challenge, login page) is never retried — no new
  session, no new IP, no full-sitemap download after a refused partial read — and goes to `FAILED_INPUTS`, not
  charged. A technical error (network, timeout, 5xx, proxy, incomplete page) gets at most 2 new tries with the same
  proxy, which stays the Moroccan residential proxy (owner exception, decided before the run). Was: up to 4 session
  rotations (pool of 5) plus 4 retries. Billing, output and run statuses unchanged.

### 2026-11-11 ("Product page checked" event for "Only changed products") — local, not deployed, price not set

- New PPE event `product-page-checked` ("Product page checked"), charged only with *Only changed products*: once per product page downloaded and parsed successfully (product found), changed or not, on top of the existing per-saved-product charge. Never for failed, blocked (anti-robot) or removed pages, nor for pages not read (page cap, rotating cursor, stop). Normal mode unchanged (no new event). New file `src/page_billing.py`.
- No double charge: pages already counted are kept in the run state (`use_state`, 6-byte URL fingerprint), so a retry or a resume after migration does not charge again.
- Safe before the price exists: the run's pricing is checked once at start; if the event is not priced (SDK 3.4.1 would otherwise log "Attempting to charge for an unknown event" on every call on the platform, and count $1 per unknown event locally), one clear warning is logged, pages are counted but not charged, and the run continues. Checked again on every run, so billing starts as soon as the owner sets the price.
- Budget: pages are queued only while their event fits in *Max cost per run* (queued pages are reserved); a refused charge means the page is not delivered and the run stops cleanly (`stopReason: "budget"`).
- `RUN_SUMMARY` / `RUN_STATS`: `pagesChecked`, `pagesCharged`, `pageEvent`, `pageEventStatus` (`charged`, `eventNotPriced`, `notPayPerEvent`); final status message: "N fiches vérifiées, M facturées (événement « product-page-checked »)."
- README *How much it costs*: event listed as proposed, not yet active (Free $0.45, Starter $0.41, Scale $0.38, Business $0.36 per 1,000 pages).
- Tests: `tests/test_page_billing.py` (5 unit + 2 end-to-end tests with the SDK's local pay-per-event mode); `tests/fake_site.py` gained blocked pages, simulated PPE pricing and the local charging log.

### 2026-11-11 (rotating catalogue cursor for "Only changed products") — local, not deployed

- With *Only changed products* and a *Maximum products* limit (i.e. whenever the page cap applies), each run now continues the catalogue where the previous run stopped instead of re-reading the sitemap from the start, wraps around after the last product (new cycle) and stops at the page cap. Over successive runs every product is checked once per cycle. New file `src/rotation.py`.
- Cursor stored in the price-history named store (`marjane-mall-price-history`), record `rotation-<scope hash>` (one per set of links + filters; `maxItems` not part of the scope): position (sitemap, offset, anchor URL to re-sync after insertions/removals), cycle number / start date / products checked, last full cycle date, sitemap sizes, last run. Saved on `persistState`, migration, abort and at the end, at the oldest product not yet read (no queued product lost). No record → starts at 0.
- Products that appear in a sitemap since its previous full read (4-byte URL fingerprints, record `rotation-<id>-urls-<sitemap>`) are read first and skipped by the cursor later in the same cycle. Removed products: unchanged behaviour.
- Sitemap `lastmod` is not used: all 382,633 entries carry the same date (2025-12-25T05:00:07Z) on 2026-11-07 and 2026-11-11.
- Transparency: status message + log ("Couverture du catalogue : X sur N produits vérifiés dans ce cycle (cycle commencé le …), prochain run à partir de la position P ; cycle complet ≈ R runs."), `RUN_SUMMARY.catalogueCoverage`, visual report warning `CATALOGUE_COVERAGE`; README section "Catalogue coverage over several runs".
- Concurrent runs with the same scope: last writer wins, nothing skipped, possible double reads; warning in the log.
- Normal mode, `maxItems: 0`, product-link-only runs and billing unchanged; no new event, no price change.
- Tests: `tests/test_rotation.py` (13 tests + 1 opt-in slow end-to-end test, `MARJANE_SLOW_TESTS=1`), fake site `tests/fake_site.py`.

### 2026-11-11 (page cap for "Only changed products") — local, not deployed

- With *Only changed products* and a *Maximum products* limit, the run stops queuing new product pages after 4 × *Maximum products* pages read (1,200 for 300) and finishes normally (SUCCEEDED). Status message, log, `RUN_SUMMARY` (`stopReason: "pagesReadCap"`, `pagesRead`, `pagesReadCap`, `pagesReadCapReached`) and the visual report (warning `PAGES_READ_CAP`) say so. No cap when *Maximum products* is 0 or in normal mode. Factor = constant `ONLY_CHANGED_PAGES_FACTOR` (`src/page_cap.py`), overridable with the hidden advanced input `onlyChangedMaxPagesFactor` (default 4, 0 = no cap). Billing unchanged: unchanged pages are never pushed, so never charged.
- `.actor/actor.json`: default memory 512 → 256 MB (peak measured 148 MB).
- Tests: `tests/test_page_cap.py` (9 tests).

### 2026-11-09 (review invitation)

- Successful runs that saved at least one result end their status message with one short, optional invitation to leave a Store review or open an issue (never on failed or empty runs); README section "Feedback and reviews". Output and billing unchanged.

### 2026-11-08 (visual kit 1.1.0)

#### Added

- `discountAmount` output field (amount saved in MAD, `null` when not on sale), in the *Overview* view and the
  report (sort *Biggest saving (MAD)*, compare row *You save*).
- Stable error `code` on every `FAILED_INPUTS` entry (`INVALID_INPUT`, `BLOCKED`, `NOT_FOUND`, `TIMEOUT`, ...; the
  existing `type` and `reason` are kept) and `failedByCode` + `antiBotPages` in `RUN_SUMMARY`.
- Visual report on kit 1.1.0: live progress page while running (at most one write per minute), at most 3 pictures
  per product, data-quality panel, failures grouped by code, coded warnings (anti-robot pages, removed products,
  budget). The report is also finalised (status FAILED) when the crawl stops on an error.

#### Tests

- `tests/test_live_report.py` (new) and `tests/test_report.py` updated for kit 1.1.0.

### 2026-11-08

#### Added

- **Visual report** (`REPORT` record, Output tab → *Visual report*): product cards with photo gallery, price,
  regular price, discount, price change since the last run, stock ("Only 3 left", out of stock), "Sold by Marjane",
  category, seller and delivery dates; compare mode (up to 4); key figures, price, discount, department and brand
  charts, search, filters, sorting, table view and CSV/JSON export of the filtered rows. Built by the shared
  `src/visual_kit.py` (v1.0.1) with this Actor's `src/report.py`. At most 2,000 rows are kept in memory for it; it
  is never billed and a report error is only logged as a warning.
- *Price changes* view: product image column, *Seen on* shown as a date. Output schema: *Visual report* link;
  key-value store schema: `REPORT` (text/html).

#### Fixed

- Image links (`image`, `images`): `//host/…` becomes `https://host/…`; blank, `data:` and relative values are
  dropped, and a picture listed twice in the product gallery is kept once. Valid links are unchanged.

#### Tests

- `tests/test_report.py`: 13 tests on 60 real products of a production run and the real product page fixture
  (image ownership, gallery, placeholders, URL normalization in the parser, escaping, a 5,000-row synthetic set,
  export = embedded data, failure safety, REPORT saved as exactly text/html, rows pushed → report with limit and duplicates).

### 2026-11-07

#### Faster and cheaper small runs

- A small run (default 100 products, or any run needing up to 5,000 sitemap entries) now reads only the beginning of the product sitemap, streamed and cut as soon as enough product links are known (measured: 7 KB downloaded instead of about 1.8 MB per sitemap). The whole file is still read, as before, when more links are needed or if the partial read fails. On Apify this traffic goes through the residential proxy, so it was most of the cost of small runs (`src/sitemap_stream.py`).
- Price history is loaded and saved with parallel requests (16 at a time) instead of 64 calls in a row at start-up (`src/price_history.py`).

#### Reliability

- Retries wait 1 s, 2 s, 4 s… with ±30 % jitter (was a fixed 2^n delay), so failed requests do not all retry at the same moment.
- Explicit 60 s timeout on every page or sitemap download (`navigation_timeout`), 30 s per attempt for the partial sitemap read, 3 attempts with a new proxy address each time.
- A Cloudflare "Just a moment" verification page is now reported as such in the logs and in `FAILED_INPUTS` (it is not bypassed; the page is simply retried later and reported if it keeps failing).
- A partial sitemap response without any product link (error page served with HTTP 200) is treated as a failure, never as an empty sitemap.

#### Input

- Booleans sent as text (`"false"`, `"0"`, `"non"`) are understood; a `proxyConfiguration` that is not an object falls back to the default (RESIDENTIAL, Morocco) with a warning instead of crashing; `maxRequestsPerMinute` ≤ 0 falls back to 180 instead of 1.
- The log no longer says "whole catalogue" when every pasted link was unusable.

#### Data

- Every row is checked against the types declared in `.actor/dataset_schema.json` before it is saved (numbers sent as text are converted, nothing is dropped) (`src/item_check.py`).
- `dataset_schema.json`: `id` and `reviewsCount` declared as integers; descriptions say when a field is often empty (rating, discount, brand, GTIN, price-tracking fields).

#### Maintenance

- Offline test suite (`tests/`, 25 tests) on a real product page, real sitemap excerpts and real rows of an Apify run; `pytest.ini`.
- `requirements.txt`: `crawlee>=1.11,<2` (version tested), `apify>=3.4,<4`. `tests/` excluded from the Docker image.
