Scrapyard

Motor de scraping y pipeline de datos autoalojado: raspa redes sociales y fuentes web, normaliza todo en un formato de envoltorio común, filtra por un registro de suscripciones y publica las coincidencias. Hoy la única fuente activa es X/Twitter.

estado
activo
Etiquetas
#python#scraping#selfhost#docker#automation
código
github ↗

Self-hosted scraping engine and data pipeline. It scrapes and streams social platforms and web sources, normalizes everything into a common envelope format, filters it against a subscription registry, and publishes matches to Valkey streams for downstream consumers — polybot’s trading agents, dataset builders, personator’s corpus harvesting, anything that subscribes.

Today the only live source is X/Twitter. The engine is built to scale to more platforms and the open web by whatever method each source needs: dedicated Python libraries, plain HTTP with user-agent and TLS tricks, or full browser automation.

Pipeline

  1. Scrape — X/Twitter via twscrape, with an account pool, cluster isolation, and per-cluster proxy assignment. Reddit, Telegram, and 4chan scrapers are stubbed.
  2. Normalize — every platform’s content becomes one envelope format (models/envelope.py)
  3. Filter — two-layer relevance against the subscription registry: Layer 1 is a compound keyword gate; Layer 2 is embedding cosine similarity against the subscription’s description (OpenAI-compatible endpoint, nomic-embed-text). Subscriptions can be gated (both layers) or ungated (raw firehose to the channel)
  4. Dedup — per-(subscription, item) via Valkey SET NX EX, before publishing
  5. Publish — Valkey Streams with consumer groups. HTTP stays admin-only; real-time delivery never touches it

The relevance/sentiment boundary is deliberate: scrapyard owns is this item on-topic, and interpretation (sentiment, trade signals, dataset inclusion) lives entirely in the consumers.

Scaling to new sources

  • Platform scrapers through dedicated libraries: twscrape now; PRAW (Reddit) and Telethon (Telegram) planned
  • Generic web through an escalating fetch chain: httpx → curl_cffi (TLS impersonation) → Playwright → stealth — each site gets the least expensive tier that works
  • All scraper egress goes through a pool of Mullvad WireGuard SOCKS5 sidecar containers (wg-pool/), with static relay assignment, staggered rotation, and identity-aligned rotation for authenticated workers

Operating it

docker compose up -d                      # Valkey + WireGuard proxy sidecars
uv sync                                   # dependencies

uv run python src/main.py                 # status: clusters, accounts, subscriptions, Valkey
uv run python src/main.py run             # scheduler + processor loop
uv run python src/main.py subscriptions sync    # subscriptions.toml → SQLite
uv run python src/main.py subscriptions list    # list all subscriptions
uv run python src/main.py twitter reload  # reload pool config without restart
uv run python src/main.py --seed          # import accounts from sessions.jsonl
uv run python src/main.py --search QUERY  # one-shot X search

A small FastAPI control plane (src/api/control.py, /health and /subscriptions/sync) exposes the management surface — this is the endpoint infradmin reads.

Configuration

TOML under config/, each with a committed .example to copy from: config.toml (Valkey, storage, embeddings, proxies, scheduler, dedup), platforms.toml (Twitter clusters, proxy assignment), subscriptions.toml (the subscription registry seed), sites.toml (web fetch, TODO). Secrets live in secrets/ (Twitter account DBs, 500+ WireGuard relay configs).

Fleet context

One piece of a self-hosted fleet: infradmin manages it, polybot consumes its streams for trading, sneaker feeds it the Mullvad relay list, and personator is the planned data side for personality datasets.

Stack

Python 3.12+ · Valkey (Streams, consumer groups) · SQLite (subscription registry) · twscrape · FastAPI/Uvicorn (admin only) · OpenAI-compatible embeddings · Docker Compose (Valkey + WireGuard SOCKS5 sidecars) · uv.