# USCF Chess Scraper (`iqraa/uscf-chess-scraper`) Actor

- **URL**: https://apify.com/iqraa/uscf-chess-scraper.md
- **Developed by:** [Iqraa Manuel](https://apify.com/iqraa) (community)
- **Categories:** Sports
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.05 / actor start

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js/docs.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python/docs.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## USCF Chess Tournament Scraper

Scrapes a US Chess Federation member's full tournament history, game-level results, and computes win-rate statistics by opponent rating bracket.

### Features

- **Modern API** (primary): Fetches structured JSON from `ratings-api.uschess.org` — no HTML parsing needed
- **Legacy fallback**: Falls back to USCF MSA + chessevents.com scraping when the API is unavailable
- **Player name search**: Look up by name if USCF ID is unknown
- **All rating systems**: Regular, Quick, Blitz, Online (R, Q, B, OR, OQ, OB)
- **Configurable brackets**: Set your own rating bucket width (default 100 points)
- **Forfeit tracking**: Records B/U/H/F/X results separately
- **Rich per-bracket stats**: Win%, draw%, loss%, scoring%, points, average opponent rating
- **Anti-detection**: Playwright stealth mode for legacy browser fallback
- **Rate limit handling**: Exponential backoff with opponent rating caching

### How it works

1. **Modern path**: Calls `ratings-api.uschess.org/api/v1/` REST API for player info, events, and games — returns clean JSON, no browser required
2. **Legacy fallback**: If the API fails, scrapes USCF MSA for tournament history and chessevents.com for crosstables (with Playwright for JS-rendered pages)
3. **Stats engine**: Aggregates games into configurable rating brackets with win/draw/loss rates, points, and average opponent rating

### Input

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `uscfId` | string | No | — | 8-digit USCF member ID (required if `playerName` is not set) |
| `playerName` | string | No | — | Player name for search, e.g. "Manuel, Iqraa" |
| `bracketSize` | integer | No | 100 | Width of opponent rating buckets for stats |
| `includeQuick` | boolean | No | false | Include quick-rated (G/15–G/30) games |
| `includeBlitz` | boolean | No | false | Include blitz-rated games |
| `includeOnline` | boolean | No | false | Include online-rated games (Chess.com) |
| `maxTournaments` | integer | No | 0 | Maximum tournaments to process (0 = all) |
| `useModernApi` | boolean | No | true | Use modern ratings API as primary source |
| `usePlaywright` | boolean | No | true | Use Playwright fallback for legacy mode |

### Example

#### Input
```json
{
  "uscfId": "30665747",
  "bracketSize": 100,
  "maxTournaments": 5
}
````

#### Output

**1. Player info**

```json
{
  "type": "player",
  "uscfId": "30665747",
  "name": "Iqraa Manuel",
  "state": "VA",
  "expiration": "2026-12-31",
  "fideId": "39971732",
  "ratings": {
    "regular": { "rating": 1872, "provisional": false },
    "quick": { "rating": 1350, "provisional": true, "gamesPlayed": 21 }
  }
}
```

**2. Tournament**

```json
{
  "type": "tournament",
  "id": "202607050483",
  "name": "54th Annual World Open",
  "startDate": "2026-07-01",
  "endDate": "2026-07-05",
  "stateCode": "DC",
  "gamesCount": 9
}
```

**3. Game**

```json
{
  "type": "game",
  "result": "loss",
  "color": "white",
  "opponent": { "name": "Alan Stolyarov", "uscfId": "14490864", "rating": 1979 },
  "eventName": "54th Annual World Open",
  "ratingSystem": "R"
}
```

**4. Summary**

```json
{
  "type": "summary",
  "source": "modern-api",
  "playerName": "Iqraa Manuel",
  "totalGames": 243,
  "wins": 138,
  "draws": 60,
  "losses": 45,
  "forfeits": 0,
  "winPercent": 56.8,
  "drawPercent": 24.7,
  "lossPercent": 18.5,
  "scoringPercent": 69.1,
  "averageOpponentRating": 1678,
   "byRatingRange": {
     "0-100":    { "games": 0, "wins": 0, "draws": 0, "losses": 0, "winPercent": 0, "scoringPercent": 0, "points": 0, "averageOpponentRating": null },
     ...
     "1600-1700": { "games": 13, "wins": 9, "draws": 2, "losses": 2, "winPercent": 69.2, "scoringPercent": 76.9, "points": 10, "averageOpponentRating": 1660 },
     ...
     "2900-3000": { "games": 0, "wins": 0, "draws": 0, "losses": 0, "winPercent": 0, "scoringPercent": 0, "points": 0, "averageOpponentRating": null }
   }
}
```

### API endpoints used (modern path)

| Endpoint | Purpose |
|---|---|
| `GET /api/v1/members/{id}` | Player profile and ratings |
| `GET /api/v1/members/{id}/events` | Tournament history |
| `GET /api/v1/members/{id}/games?eventId=X` | Game-level results per event |

### Use cases

- **Coaches**: Track student progress across tournaments
- **Players**: Get a complete picture of your career statistics
- **Analysts**: Study performance patterns by opponent rating range
- **Parents**: Monitor junior player development

### Deployment

#### Local development

```bash
pip install -r requirements.txt
python -m src.main
```

#### Apify

```bash
apify push
```

# Actor input Schema

## `uscfId` (type: `string`):

The 8-digit US Chess Federation member ID (e.g. 30665747). Required if playerName is not set.

## `playerName` (type: `string`):

Search by player name (last, first) if USCF ID is unknown. Used when uscfId is empty.

## `bracketSize` (type: `integer`):

Width of each opponent rating bucket for stats (e.g. 100 = 0-99, 100-199, etc.)

## `includeQuick` (type: `boolean`):

Also scrape quick-rated (G/15–G/30) games

## `includeBlitz` (type: `boolean`):

Also scrape blitz-rated games

## `includeOnline` (type: `boolean`):

Also scrape online regular/quick/blitz games (from Chess.com)

## `useModernApi` (type: `boolean`):

Use the modern ratings-api.uschess.org REST API as the primary data source. Falls back to legacy MSA if the API fails.

## `usePlaywright` (type: `boolean`):

Fall back to a headless browser when HTTP scraping finds no crosstable (legacy mode only).

## `maxTournaments` (type: `integer`):

Maximum number of tournaments to process (0 = unlimited)

## `crosstableSources` (type: `array`):

Crosstable provider used for game-level details. Tournament history always comes from US Chess MSA.

## Actor input object example

```json
{
  "bracketSize": 100,
  "includeQuick": false,
  "includeBlitz": false,
  "includeOnline": false,
  "useModernApi": true,
  "usePlaywright": true,
  "maxTournaments": 0,
  "crosstableSources": [
    "chessevents"
  ]
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("iqraa/uscf-chess-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("iqraa/uscf-chess-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call iqraa/uscf-chess-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=iqraa/uscf-chess-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "USCF Chess Scraper",
        "version": "1.0",
        "x-build-id": "1LOUheqZynOL4GPLb"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/iqraa~uscf-chess-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-iqraa-uscf-chess-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/iqraa~uscf-chess-scraper/runs": {
            "post": {
                "operationId": "runs-sync-iqraa-uscf-chess-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/iqraa~uscf-chess-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-iqraa-uscf-chess-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "uscfId": {
                        "title": "USCF Member ID",
                        "pattern": "^\\d{8}$",
                        "type": "string",
                        "description": "The 8-digit US Chess Federation member ID (e.g. 30665747). Required if playerName is not set."
                    },
                    "playerName": {
                        "title": "Player name",
                        "type": "string",
                        "description": "Search by player name (last, first) if USCF ID is unknown. Used when uscfId is empty."
                    },
                    "bracketSize": {
                        "title": "Rating bracket size",
                        "minimum": 25,
                        "maximum": 500,
                        "type": "integer",
                        "description": "Width of each opponent rating bucket for stats (e.g. 100 = 0-99, 100-199, etc.)",
                        "default": 100
                    },
                    "includeQuick": {
                        "title": "Include Quick rated games",
                        "type": "boolean",
                        "description": "Also scrape quick-rated (G/15–G/30) games",
                        "default": false
                    },
                    "includeBlitz": {
                        "title": "Include Blitz rated games",
                        "type": "boolean",
                        "description": "Also scrape blitz-rated games",
                        "default": false
                    },
                    "includeOnline": {
                        "title": "Include Online rated games",
                        "type": "boolean",
                        "description": "Also scrape online regular/quick/blitz games (from Chess.com)",
                        "default": false
                    },
                    "useModernApi": {
                        "title": "Use modern USCF API",
                        "type": "boolean",
                        "description": "Use the modern ratings-api.uschess.org REST API as the primary data source. Falls back to legacy MSA if the API fails.",
                        "default": true
                    },
                    "usePlaywright": {
                        "title": "Use Playwright (browser) for JS-rendered pages",
                        "type": "boolean",
                        "description": "Fall back to a headless browser when HTTP scraping finds no crosstable (legacy mode only).",
                        "default": true
                    },
                    "maxTournaments": {
                        "title": "Max tournaments",
                        "minimum": 0,
                        "maximum": 200,
                        "type": "integer",
                        "description": "Maximum number of tournaments to process (0 = unlimited)",
                        "default": 0
                    },
                    "crosstableSources": {
                        "title": "Crosstable sources to try",
                        "type": "array",
                        "description": "Crosstable provider used for game-level details. Tournament history always comes from US Chess MSA.",
                        "items": {
                            "type": "string",
                            "enum": [
                                "chessevents"
                            ],
                            "enumTitles": [
                                "CCA / chessevents.com"
                            ]
                        },
                        "default": [
                            "chessevents"
                        ]
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
