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.
Scrapes the Mega Millions draw-data API on a schedule and stores each draw in SQLite.
Rendering mermaid diagram...
| File | Type | Purpose |
|---|---|---|
scraper.ts | interval | Cron entrypoint. Runs every 15 min, scrapes the most recent 4 draws. |
ticks.ts | script | Converts dates ⇄ .NET "ticks" and figures out recent Tue/Fri draw dates. |
parse.ts | script | Fetches the API and unwraps the XML-wrapped JSON payload. |
db.ts | script | SQLite schema + upsert (keyed on play_date_ticks). |
viewer.ts | http | GET / → latest 20 draws as JSON. GET /?ticks=<n> → full raw payload. |
- The API returns XML-wrapped JSON.
parse.tsstrips the<string>…</string>wrapper and decodes HTML entities beforeJSON.parse. .NETticks exceed JS's safe integer range, so they're handled withBigIntand 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.
Edit the interval on scraper.ts. Current: */15 * * * * (every 15 min).
For hourly use 0 * * * *.