Skip to content

The Content Automation Pipeline

One continuous chain:

monitor source → scrape → process/generate → publish → log

Typical use: watch several sources, translate or rewrite what’s new, and publish — no human in the loop.

Principle 1: scripts must run without interaction

Section titled “Principle 1: scripts must run without interaction”

Nothing is there to answer a prompt. Anything waiting on input hangs forever.

// ❌ hangs
const answer = await prompt('Publish now?')
// ✅ configuration instead
const BACKFILL_ENABLED = false
const HEADLESS = true

Turn every decision point into a config value up front.

终端窗口
node monitor.js >> cron.log 2>&1

Automation without logs means guessing when something breaks. Record what ran, how many items were found, how many succeeded, and why failures failed.

A freshly deployed monitor without bounds will republish months of old content.

Track processed IDs, and put historical backfill behind a flag that’s off by default.

Running twice shouldn’t duplicate output. Record what’s been processed and skip it next time.

Network Some sources need a proxy depending on your region. Configure it explicitly in the script; don’t rely on system settings.

Page loading Waiting for networkidle times out constantly. Switch to domcontentloaded plus an explicit wait for the target element — much more reliable.

Being polite Throttle requests, set reasonable headers, and space out batch scraping.

Scraped content usually needs work:

  • Translation (specify target language, preserve proper nouns)
  • Rewriting (restructure and resize for the destination platform)
  • Formatting (match platform conventions)

Always keep source links and attribution — both respect and traceability.

When publishing through an API:

  1. Test with scheduled publishing first, not immediate — review, then release manually
  2. Record publish results (successful and failed IDs)
  3. Retry transient failures carefully, guarding against duplicates
config.js
module.exports = {
accounts: ['@account1', '@account2'],
checkInterval: '0 */2 * * *',
headless: true,
proxy: 'http://127.0.0.1:7897',
backfillEnabled: false, // historical republish, default off
logFile: './cron.log',
publishMode: 'scheduled', // schedule, don't publish immediately
}

Launching isn’t the finish line — you need to know when it dies:

  • N consecutive failures → needs human attention
  • No output for a long stretch → the source may have changed structure
  • Read the log manually once a week

The most overlooked failure mode: a source redesigns, selectors stop matching, and you scrape empty results. This “silent failure” is the worst kind — the job looks healthy and produces nothing.

Five scenarios, one recurring method: scan read-only first, batch the changes, write logs, leave yourself an undo.

Next: the Power User track.