GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tgtg-python/CLAUDE.md at master · ahivert/tgtg-python

Expand file tree

/

CLAUDE.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
79 lines (53 loc) · 3.41 KB
/

CLAUDE.md

Copy path

File metadata and controls

79 lines (53 loc) · 3.41 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

AGENTS.md

This file provides guidance to agents when working with code in this repository.

Project Overview

Unofficial Python client for the TooGoodToGo API. Published on PyPI as tgtg. Python 3.11+. Licensed under GPL-3.0.

Commands

# Install dependencies (requires uv)
pipx install uv

# Then install project deps
uv sync

# Run all tests (with coverage)
make test

# Run a single test file
uv run pytest tests/test_login.py

# Run a single test function
uv run pytest tests/test_login.py::test_login_success

# Run linting (ruff check + format)
make lint

# Build and publish to PyPI
make publish

Code Style

  • Formatter: Ruff (uses Black-compatible formatting)
  • Linter: Ruff (selects E, F, W rules)
  • All enforced via make lint

Architecture

The entire library is a single class TgtgClient in tgtg/__init__.py (~522 lines). There are no subpackages or complex abstractions.

Key components

  • tgtg/__init__.py - TgtgClient class plus all API endpoint constants. Every public method calls self.login() first, which handles token refresh automatically. The client uses requests.Session for HTTP, with Android user-agent spoofing. All API calls go through the central _post() method which handles DataDome cookie management and 403 retry logic.
  • tgtg/exceptions.py - Three exception types: TgtgLoginError, TgtgAPIError, TgtgPollingError.
  • tgtg/google_play_scraper.py - Scrapes the Google Play Store page to get the current TooGoodToGo APK version for user-agent strings. Falls back to DEFAULT_APK_VERSION.

DataDome bot protection

TooGoodToGo uses DataDome for bot protection. The client handles this by:

  1. Fetching a datadome cookie from https://api-sdk.datadome.co/sdk/ before API requests, mimicking the Android app's DataDome SDK integration (device fingerprint parameters like model, OS version, screen size).
  2. The _post() method automatically ensures a DataDome cookie is present. On 403, it invalidates the cookie and retries with a fresh one.
  3. The _generate_datadome_cid() helper creates random 120-char client IDs matching DataDome's expected format.
  4. VPN/datacenter IPs are frequently blocked by DataDome regardless of cookie validity — residential IPs work best.

Authentication flow

  1. Email-based login sends a request to auth/v5/authByEmail
  2. User receives a PIN code via email
  3. Client submits PIN via auth/v5/authByRequestPin to complete authentication
  4. Fallback: client can also poll auth/v5/authByRequestPollingId (legacy link-click flow)
  5. On success, stores access_token, refresh_token, and cookie
  6. Tokens auto-refresh after access_token_lifetime (default 4 hours)

API versions in use

Auth endpoints use v5, item endpoints use v8, order endpoints use v8, token refresh uses v1, favorites use v1, discover uses v1.

Testing

  • Framework: pytest with responses library for HTTP mocking
  • Coverage: branch coverage enabled, configured in pyproject.toml (addopts = --cov=tgtg)
  • Tests in tests/ use fixtures from conftest.py that mock auth/refresh endpoints
  • tests/constants.py contains expected API response property lists and fake token credentials
  • test_api.py contains integration tests marked @pytest.mark.withoutresponses that hit the real API (requires TGTG_EMAIL env var)
  • Time-dependent tests use freezegun for mocking datetime.datetime.now()
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.