When multiple config/sites/*.json exist, probe each via REST users/me;
aggregate { ok, sites } on stdout. Incomplete site files fail fast.
Made-with: Cursor
AI News Writer
Autonomous news writing system for BitReport. Researches news from trusted sources, detects topics, and writes complete articles like a professional journalist — then exports to WordPress.
Paperclip issue: BIT-353
Gitea: https://git.bitreport.pt/BitReport.pt/ai-news-writer
Dev container: ai-news-writer-dev (planned CTID 223, VLAN 1050 — created only after you run tools/proxmox/create_ai_news_writer_lxc.sh on a Proxmox node)
Domain: ainews.bitreport.pt (NPM configured manually)
Quick start
cp .env.example .env
# fill OPENAI_API_KEY in .env
npm install
node src/index.js write "FC Porto match result"
Commands
| Command | Description |
|---|---|
npm run write |
Write one article (manual mode) |
npm run write -- "topic" |
Write article about specific topic |
npm run listen |
Start auto RSS listener (cron) |
npm run pm2:start |
PM2 via ecosystem.config.cjs (requires global pm2) |
npm run verify:deploy -- <url> |
Smoke-test GET /health (expects listen mode); needs curl + node |
npm run wp:test |
GET /wp-json/wp/v2/users/me — validates every config/sites/*.json (excl. example), or WP_* env if no site files |
npm start |
Same as write |
npm run dev |
Auto-restart with nodemon |
Architecture
RSS Feeds / News Sites
↓
src/crawler/rss.js — fetch + normalize RSS articles
src/crawler/scraper.js — scrape full article content
↓
src/writer/ai.js — OpenAI journalist AI
↓
src/publisher/wordpress.js — WP REST API export
↓
WordPress (draft/publish)
Listener / auto mode:
src/listener/rss-listener.js — cron-based RSS polling
↓
detectTopics() → generateArticle() → publishToWordPress()
Configuration
Sources (config/sources.json)
Edit to add/remove RSS feeds, keywords, and trusted domains.
Sites (config/sites/*.json)
One JSON file per WordPress target site. Copy config/sites/example.json.
Credentials come from your vault — never commit real passwords.
npm run wp:test checks each site file (or env fallback if config/sites/ has no JSON except example); stdout is one JSON object { "ok": boolean, "sites": [ ... ] } and the process exits non-zero if any check fails.
{
"name": "sports news",
"wp_url": "https://wp.newsproject.bitreport.pt",
"user": "wp-api-user",
"password": "application-password-from-vault",
"category_default": 5,
"status_default": "draft",
"lang": "pt"
}
Environment variables (.env)
| Variable | Purpose |
|---|---|
OPENAI_API_KEY |
OpenAI API key |
AI_MODEL |
Model (default: gpt-4o) |
HOST |
HTTP bind address in listen mode (default: 0.0.0.0) |
PORT |
HTTP port in listen mode (default: 3200) |
WP_URL |
WordPress base URL (fallback) |
WP_USER |
WP application username |
WP_PASSWORD |
WP application password |
MODE |
auto or manual |
AUTO_CRON |
Cron expression for auto mode |
LOG_LEVEL |
debug, info, warn, error |
Article output format
{
"title": "...",
"subtitle": "...",
"slug": "url-safe-slug",
"body": "<p>...</p>",
"summary": "...",
"tags": ["...", "..."],
"category": "sports",
"seo_title": "...",
"seo_description": "..."
}
Deploy (LXC dev container)
The public URL (ainews.bitreport.pt) expects something listening on PORT (default 3200) on the LXC. In listen mode the app starts a small HTTP server on HOST:PORT (HOST defaults to 0.0.0.0) so NPM can proxy to it. npm start / write does not start HTTP — use listen for long-running + NPM.
Was the LXC actually created?
Nothing in this repository creates Proxmox containers by itself. The bash script must be executed as root on a Proxmox node. If CT 223 (or ai-news-writer-dev) does not appear in pct list, the container was never provisioned.
(Nota PT: o domínio só responde se o CT existir, o Node estiver em modo listen na porta 3200, e o NPM apontar para o IP real desse CT — não assumir 10.10.50.23 sem confirmar no Proxmox.)
# --- On the Proxmox host (SSH as root) — create CT if missing ---
pct list | grep -E '223|ai-news-writer'
# If no row, from a clone of this repo:
bash tools/proxmox/create_ai_news_writer_lxc.sh
# Confirm guest IP for NPM (example VMID 223)
pct exec 223 -- ip -4 addr show eth0
# --- Inside the CT ---
git clone https://git.bitreport.pt/BitReport.pt/ai-news-writer.git /srv/ai-news-writer
cd /srv/ai-news-writer
npm install
cp .env.example .env
# edit .env: OPENAI_API_KEY, HOST=0.0.0.0, PORT=3200
# pm2 delete ai-news-writer # only if replacing an old one-shot / wrong-args process
pm2 start ecosystem.config.cjs
pm2 save && pm2 startup
(Alternative, easier to mistype: pm2 start src/index.js --name ai-news-writer --cwd /srv/ai-news-writer --time -- listen — the -- before listen is required.)
NPM (CT 102): Proxy Host ainews.bitreport.pt → http://<lxc-ip>:3200 (forward scheme http unless you terminate TLS only at NPM). Quick check from another machine: curl -sS http://<lxc-ip>:3200/health — JSON includes version and mode: "listen" so you can confirm the running build (and that this is not a one-shot write process).
Structured check (exit code 0/1): from a machine with curl + node (e.g. the CT or your laptop):
./tools/verify-deploy.sh "http://<lxc-ip>:3200"
# or: npm run verify:deploy -- "http://<lxc-ip>:3200"
Typo check: the hostname must be ainews.bitreport.pt (not ainews.bitrepor.pt).
Future
- Multi-language output
- Auto-schedule & publish
- Image generation (DALL-E / Stable Diffusion)
- SEO scoring
- Telegram / Discord social listening
- Web dashboard (approve / edit / publish UI)