Public
Scrapes Mega Millions draw data on a schedule into SQLite
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

Mega Millions Scraper

Scrapes the Mega Millions draw-data API on a schedule and stores each draw in SQLite.

How it works

Rendering mermaid diagram...

Files

FileTypePurpose
scraper.tsintervalCron entrypoint. Runs every 15 min, scrapes the most recent 4 draws.
ticks.tsscriptConverts dates ⇄ .NET "ticks" and figures out recent Tue/Fri draw dates.
parse.tsscriptFetches the API and unwraps the XML-wrapped JSON payload.
db.tsscriptSQLite schema + upsert (keyed on play_date_ticks).
viewer.tshttpGET / → latest 20 draws as JSON. GET /?ticks=<n> → full raw payload.

Notes

  • The API returns XML-wrapped JSON. parse.ts strips the <string>…</string> wrapper and decodes HTML entities before JSON.parse.
  • .NET ticks exceed JS's safe integer range, so they're handled with BigInt and stored/queried as TEXT. Storing them as INTEGER causes a libSQL "integer too large" error.
  • Cron runs in UTC. Draw dates are computed on a UTC date basis.
  • The scraper re-scrapes the latest few draws each run (upsert), so jackpot amounts and winner counts stay fresh as they're finalized after each draw.

Changing the schedule

Edit the interval on scraper.ts. Current: */15 * * * * (every 15 min). For hourly use 0 * * * *.