Logo Lanfrica

joelfickson/malawi-x-trending

Domain:

natural language processing

Record type:

software
Creator:
joe
Host:
Cloudflare Worker that pulls Malawi-geotagged tweets every 6h, summarizes them with Workers AI, and serves a TanStack Start dashboard. # malawi-x-trending A Cloudflare Worker that pulls tweets posted from Malawi every 6 hours, summarizes the topics being discussed using Workers AI, and serves a dashboard at x.fickson.com. ## Architecture ``` Cron Trigger (every 6h) | v +----------------------+ | Worker (scheduled) | | 1. X API search | place_country:MW -is:retweet, max_results=100 | 2. expand top convs | conversation_id: for top originals (optional) | 3. extract counts | hashtags, mentions, n-grams | 4. Workers AI | Llama 3.1 8B Fast - topic JSON | 5. write D1 + KV | +----------------------+ | v Worker (HTTP) / and the route pattern ``` ### 2. Create D1 database and KV namespace ```bash npx wrangler d1 create malawi-trending # copy the database_id into wrangler.toml [[d1_databases]] section npx wrangler kv namespace create CACHE # copy the id into wrangler.toml [[kv_namespaces]] section ``` ### 3. Initialize the schema ```bash npm run db:init:remote # production DB # for local dev: npx wrangler d1 execute malawi-trending --local --file=schema.sql ``` ### 4. Set the bearer token secret ```bash npx wrangler secret put X_BEARER_TOKEN # paste your X API bearer token when prompted ``` ### 5. Connect the custom domain In the Cloudflare dashboard: zone `fickson.com` -> DNS -> add a `CNAME` `x` -> `malawi-x-trending. .workers.dev` (proxied). The `[[routes]]` entry in `wrangler.toml` declares `x.fickson.com` as a custom domain - on first deploy, Cloudflare automatically creates the route mapping. You may need to verify zone ownership. ### 6. Deploy ```bash npm run deploy ``` ## Local development ```bash cp .dev.vars.example .dev.vars # edit .dev.vars and paste the bearer token npm run dev ``` Open the URL printed by Vite (default `localhost`) to see the dashboard. The Vite dev server runs the HTTP handler but not the scheduled handler. To trigger a fetch cycle locally, hit the admin endpoint with the local admin token (last 16 c …