Simplify Threads captions and capture five minutes after sunrise
This commit is contained in:
@@ -5,7 +5,7 @@ import { setTimeout as delay } from 'node:timers/promises';
|
||||
import { chromium } from 'playwright';
|
||||
import { THREADS } from '../../src/constants/threads.ts';
|
||||
import { kstClock, kstFields } from '../../src/ui/time.ts';
|
||||
import { dailySchedule, publishCarousel, threadsRequest } from './publisher.ts';
|
||||
import { dailySchedule, publishCarousel, threadsRequest, sunriseCaptureTime } from './publisher.ts';
|
||||
import { loadThreadsConfig } from './config.ts';
|
||||
import { cleanupPublished } from './cleanup.ts';
|
||||
import { loadCaptions, renderCaption } from './captions.ts';
|
||||
@@ -79,8 +79,8 @@ async function main() {
|
||||
const immediate = postNow || (dryRun && args.includes('--now'));
|
||||
const capturePath = join(stateDir, `${runId}.capture.json`);
|
||||
const savedCapture = dryRun ? null : await readJson(capturePath);
|
||||
if (!savedCapture && !immediate && Date.now() > +schedule.sunrise + THREADS.maxLatenessMs) {
|
||||
console.log(`${schedule.date}: sunrise has passed; skipping late capture`);
|
||||
if (!savedCapture && !immediate && Date.now() > +schedule.captureAt + THREADS.maxLatenessMs) {
|
||||
console.log(`${schedule.date}: sunrise +5 minute capture window has passed; skipping late capture`);
|
||||
return;
|
||||
}
|
||||
const captured = savedCapture ?? await captureSunrise(schedule, immediate);
|
||||
@@ -142,14 +142,16 @@ async function captureSunrise(schedule: ReturnType<typeof dailySchedule>, immedi
|
||||
sunrise = new Date(await page.evaluate(() => window.sunriseThreads!.sunrise()));
|
||||
if (!Number.isFinite(+sunrise) || kstFields(sunrise).date !== schedule.date) throw new Error('Unexpected page sunrise date');
|
||||
console.log(`Page sunrise: ${sunrise.toISOString()} (${kstClock(sunrise)} KST)`);
|
||||
const captureAt = sunriseCaptureTime(sunrise);
|
||||
console.log(`Capture target: ${captureAt.toISOString()} (${kstClock(captureAt)} KST)`);
|
||||
if (!immediate) {
|
||||
if (Date.now() > +sunrise + THREADS.maxLatenessMs) throw new Error('Page loaded after capture deadline');
|
||||
await waitUntil(sunrise);
|
||||
if (Date.now() > +captureAt + THREADS.maxLatenessMs) throw new Error('Page loaded after capture deadline');
|
||||
await waitUntil(captureAt);
|
||||
}
|
||||
const capture = await page.evaluate(() => window.sunriseThreads!.capture());
|
||||
capturedAt = capture.capturedAt;
|
||||
weather = capture.weather ?? null;
|
||||
if (!immediate && Math.abs(Date.parse(capturedAt) - +sunrise) > THREADS.maxLatenessMs) throw new Error('Capture missed sunrise deadline');
|
||||
if (!immediate && Math.abs(Date.parse(capturedAt) - +captureAt) > THREADS.maxLatenessMs) throw new Error('Capture missed sunrise +5 minute deadline');
|
||||
if (capture.images?.length !== THREADS.angles.length) throw new Error('Deploy the two-angle capture frontend first');
|
||||
for (const [index, shot] of capture.images.entries()) {
|
||||
if (shot.name !== THREADS.angles[index].name) throw new Error('Unexpected capture angle order');
|
||||
|
||||
Reference in New Issue
Block a user