-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawl-issues.js
More file actions
executable file
·666 lines (560 loc) · 20.3 KB
/
crawl-issues.js
File metadata and controls
executable file
·666 lines (560 loc) · 20.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#!/usr/bin/env node
/**
* Crawl Workback issues and create markdown dossiers in issues/<id>/issue-<id>.md
*
* Uses curl + cheerio (no browser required). Pass cookies via --cookie flag.
*
* Usage:
* node crawl-issues.js --cookie "csrftoken=...; sessionid=..."
* node crawl-issues.js --from-csv --missing-only --cookie "csrftoken=...; sessionid=..."
* node crawl-issues.js --ids-file /tmp/workback-live-ids-uniq.txt --missing-only --cookie "csrftoken=...; sessionid=..."
* node crawl-issues.js --discover-new --discover-pages 8 --cookie "csrftoken=...; sessionid=..."
* node crawl-issues.js --from-csv --missing-only --dry-run
* node crawl-issues.js --fix-images --cookie "csrftoken=...; sessionid=..."
*/
import { execSync } from 'child_process';
import { writeFileSync, mkdirSync, existsSync, readdirSync, readFileSync } from 'fs';
import { join } from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { load as cheerioLoad } from 'cheerio';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const BASE_URL = 'https://app.workback.ai';
const ISSUES_DIR = join(__dirname, 'issues');
const PROGRESS_FILE = join(ISSUES_DIR, 'crawl-progress.json');
const ERROR_LOG = join(ISSUES_DIR, 'crawl-errors.log');
const EXPORT_CSV = join(__dirname, 'export.csv');
const DEFAULT_DISCOVER_PAGES = 8;
const DEFAULT_STOP_AFTER_STALE_PAGES = 2;
const ISSUE_IDS = [
4226, 4221, 4215, 4208, 4204, 4194, 4189, 4185, 4180, 4171, 4164, 4161, 4144,
3938, 3935, 3934, 3933, 3932, 3931, 3930, 3929, 3928, 3927, 3919, 3917, 3909,
3904, 3902, 3897, 3896, 3885, 3883, 3878, 3868, 3867, 3866, 3853, 3852, 3850,
3834, 3828, 3748, 3744, 3742, 3739, 3737, 3731, 3727, 3717, 3716, 3715, 3712,
3701, 3697, 3687, 3682, 3676, 3668, 3650, 3642, 3640, 3634, 3631, 3628, 3627,
3626, 3621, 3620, 3619, 3618, 3617, 3615, 3614, 3598, 3590, 3586, 3585, 3582,
3575, 3562, 3561, 3558, 3557, 3556, 3550, 3548, 3545, 3514, 3505, 3490, 3485,
3479, 3460, 3450, 3448, 3447, 3443, 3440, 3429, 3427, 3421, 3420, 3410, 3407
];
const CURL_HEADERS = [
'-H', 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
'-H', 'accept-language: en,ru;q=0.9',
'-H', 'referer: https://app.workback.ai/issues/',
'-H', 'sec-ch-ua: "Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144"',
'-H', 'sec-ch-ua-mobile: ?0',
'-H', 'sec-ch-ua-platform: "macOS"',
'-H', 'sec-fetch-dest: document',
'-H', 'sec-fetch-mode: navigate',
'-H', 'sec-fetch-site: same-origin',
'-H', 'sec-fetch-user: ?1',
'-H', 'upgrade-insecure-requests: 1',
'-H', 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36',
];
// --- CLI args ---
function getCookieArg() {
const idx = process.argv.indexOf('--cookie');
if (idx === -1 || idx + 1 >= process.argv.length) return null;
return process.argv[idx + 1];
}
function getIdsFileArg() {
const idx = process.argv.indexOf('--ids-file');
if (idx === -1 || idx + 1 >= process.argv.length) return null;
return process.argv[idx + 1];
}
function getIntArg(flagName, defaultValue) {
const idx = process.argv.indexOf(flagName);
if (idx === -1 || idx + 1 >= process.argv.length) return defaultValue;
const parsed = Number.parseInt(process.argv[idx + 1], 10);
if (!Number.isInteger(parsed) || parsed <= 0) {
throw new Error(`${flagName} must be a positive integer`);
}
return parsed;
}
// --- ID helpers ---
function getIdsFromCsv() {
const csv = readFileSync(EXPORT_CSV, 'utf8');
const lines = csv.split('\n').slice(2);
return lines
.map((line) => line.match(/^"(\d+)"/)?.[1])
.filter(Boolean)
.map(Number);
}
function getIdsFromFile(filePath) {
const content = readFileSync(filePath, 'utf8');
return [...new Set(
content
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean)
.map((line) => line.match(/\d+/)?.[0])
.filter(Boolean)
.map(Number)
)];
}
function getExistingIds() {
if (!existsSync(ISSUES_DIR)) return [];
return readdirSync(ISSUES_DIR)
.filter((d) => /^\d+$/.test(d))
.filter((d) => existsSync(join(ISSUES_DIR, d, `issue-${d}.md`)))
.map(Number);
}
function getIdsToCrawl(fromCsv, idsFile, missingOnly) {
let ids = ISSUE_IDS;
if (idsFile) {
ids = getIdsFromFile(idsFile);
} else if (fromCsv) {
ids = getIdsFromCsv();
}
if (missingOnly) {
const existing = getExistingIds();
ids = ids.filter((id) => !existing.includes(id));
}
return ids;
}
function getIssueIdsFromApi(cookie) {
const apiUrl = `${BASE_URL}/api/org/wcag-issues`;
const responseText = curlFetch(apiUrl, cookie);
let payload;
try {
payload = JSON.parse(responseText);
} catch {
throw new Error('Could not parse /api/org/wcag-issues response as JSON.');
}
if (!Array.isArray(payload?.data)) {
throw new Error('Unexpected /api/org/wcag-issues payload shape (missing data array).');
}
const ids = payload.data
.map((issue) => Number.parseInt(issue?.id, 10))
.filter((id) => Number.isInteger(id));
if (ids.length === 0) {
throw new Error('No issue IDs returned by /api/org/wcag-issues.');
}
return [...new Set(ids)];
}
function getIssueIdsFromHtml(html) {
const ids = [];
const seen = new Set();
const issueHrefRegex = /\/issues\/(\d+)\/?/g;
let match;
while ((match = issueHrefRegex.exec(html)) !== null) {
const id = Number.parseInt(match[1], 10);
if (!Number.isInteger(id) || seen.has(id)) continue;
seen.add(id);
ids.push(id);
}
return ids;
}
function getIssueListPageUrl(pageNumber) {
return pageNumber === 1
? `${BASE_URL}/issues/`
: `${BASE_URL}/issues/?page=${pageNumber}`;
}
function discoverNewIssueIds(cookie, maxPages, stopAfterStalePages) {
const existingIds = new Set(getExistingIds());
try {
const apiIds = getIssueIdsFromApi(cookie);
const newFromApi = apiIds
.filter((id) => !existingIds.has(id))
.sort((a, b) => b - a);
console.log(
`Discovered ${newFromApi.length} new issue(s) from API (${apiIds.length} total issue(s) returned).`
);
return newFromApi;
} catch (error) {
console.warn(`API discovery failed, falling back to HTML page scan: ${error.message}`);
}
const discoveredNewIds = [];
const seenInDiscovery = new Set();
let stalePages = 0;
let lastPageFingerprint = null;
console.log(
`Discovering new issues from Workback (max pages: ${maxPages}, stop after ${stopAfterStalePages} stale page(s))...`
);
for (let page = 1; page <= maxPages; page++) {
const pageUrl = getIssueListPageUrl(page);
const html = curlFetch(pageUrl, cookie);
const pageIds = getIssueIdsFromHtml(html);
if (page === 1 && pageIds.length === 0) {
throw new Error('No issue links found on /issues/. Session may have expired or access is denied.');
}
if (pageIds.length === 0) {
console.log(` Page ${page}: no issue links found, stopping.`);
break;
}
const pageFingerprint = pageIds.slice(0, 30).join(',');
if (lastPageFingerprint && pageFingerprint === lastPageFingerprint) {
console.log(` Page ${page}: same content as previous page, stopping.`);
break;
}
lastPageFingerprint = pageFingerprint;
const newOnPage = [];
for (const id of pageIds) {
if (seenInDiscovery.has(id)) continue;
seenInDiscovery.add(id);
if (!existingIds.has(id)) {
newOnPage.push(id);
}
}
discoveredNewIds.push(...newOnPage);
console.log(` Page ${page}: found ${pageIds.length} issue link(s), ${newOnPage.length} new.`);
if (newOnPage.length === 0) {
stalePages += 1;
} else {
stalePages = 0;
}
if (stalePages >= stopAfterStalePages) {
console.log(` Stopping after ${stalePages} stale page(s).`);
break;
}
}
const deduped = [...new Set(discoveredNewIds)].sort((a, b) => b - a);
console.log(`Discovered ${deduped.length} new issue(s).`);
return deduped;
}
// --- Logging & progress ---
function logError(message) {
const timestamp = new Date().toISOString();
writeFileSync(ERROR_LOG, `[${timestamp}] ${message}\n`, { flag: 'a' });
console.error(`ERROR: ${message}`);
}
function loadProgress() {
if (existsSync(PROGRESS_FILE)) {
try {
return JSON.parse(readFileSync(PROGRESS_FILE, 'utf8'));
} catch {
return { completed: [], failed: [], current: null };
}
}
return { completed: [], failed: [], current: null };
}
function saveProgress(progress) {
writeFileSync(PROGRESS_FILE, JSON.stringify(progress, null, 2));
}
// --- curl helpers ---
function curlFetch(url, cookie) {
const args = [
'curl', '-s', '-L',
'-b', cookie,
...CURL_HEADERS,
url,
];
const result = execSync(args.map(a => `'${a.replace(/'/g, "'\\''")}'`).join(' '), {
encoding: 'utf-8',
maxBuffer: 50 * 1024 * 1024,
shell: true,
});
return result;
}
function curlDownload(url, outputPath, cookie) {
const args = [
'curl', '-s', '-L',
'-b', cookie,
...CURL_HEADERS,
'-o', outputPath,
url,
];
execSync(args.map(a => `'${a.replace(/'/g, "'\\''")}'`).join(' '), {
encoding: 'utf-8',
maxBuffer: 50 * 1024 * 1024,
shell: true,
});
}
// --- HTML extraction with cheerio ---
function extractIssueContent(issueId, cookie) {
console.log(`\nExtracting issue ${issueId}...`);
const issueUrl = `${BASE_URL}/issues/${issueId}/`;
const html = curlFetch(issueUrl, cookie);
if (!html || html.length < 500) {
throw new Error(`Empty or too-short response for issue ${issueId} (${html.length} bytes). Session may have expired.`);
}
const $ = cheerioLoad(html);
const title = $('h1').first().text().trim();
if (!title) {
throw new Error(`No <h1> found for issue ${issueId}. Page may be a login redirect.`);
}
// Extract metadata from .meta-item elements
const metadata = {
wcag: '',
severity: '',
status: '',
stage: '',
flow: '',
pageUrl: '',
auditDate: '',
};
$('.meta-item').each((_, el) => {
const label = $(el).find('.meta-label').text().replace(':', '').trim();
// Get text value, stripping SVGs and extra whitespace
const valueEl = $(el).children().not('.meta-label').first();
let value;
if (valueEl.is('a')) {
value = valueEl.attr('href') || valueEl.text().trim();
} else {
value = valueEl.text().trim();
}
const key = label.toLowerCase().replace(/\s+/g, '');
if (key === 'wcag') metadata.wcag = value;
else if (key === 'severity') metadata.severity = value;
else if (key === 'status') metadata.status = value;
else if (key === 'stage') metadata.stage = value;
else if (key === 'flow') metadata.flow = value;
else if (key === 'pageurl') metadata.pageUrl = value;
else if (key === 'auditdate') metadata.auditDate = value;
});
// Extract sections by h2 headings
const sections = {};
$('h2').each((_, h2El) => {
const sectionName = $(h2El).text().trim();
if (!sectionName || sectionName === 'Activity') return;
if (sectionName === 'Audit Evidence') {
sections[sectionName] = 'See images section below.';
return;
}
let content = '';
let next = $(h2El).next();
while (next.length && !next.is('h2') && !next.is('h1')) {
const tag = next.prop('tagName')?.toUpperCase();
if (tag === 'P') {
content += next.text().trim() + '\n\n';
} else if (tag === 'UL' || tag === 'OL') {
next.find('li').each((_, li) => {
content += '- ' + $(li).text().trim() + '\n';
});
content += '\n';
} else if (tag === 'PRE') {
content += '\n```\n' + next.text() + '\n```\n\n';
} else if (tag === 'CODE') {
content += '`' + next.text() + '` ';
} else if (next.text().trim()) {
content += next.text().trim() + '\n\n';
}
next = next.next();
}
if (content.trim()) {
sections[sectionName] = content.trim();
}
});
// Extract images (links to /api/gcs or /api/org/gcs)
const images = [];
$('a[href*="/api/"]').each((_, linkEl) => {
const href = $(linkEl).attr('href');
if (!href || (!href.includes('/gcs') && !href.includes('/api/org/'))) return;
const img = $(linkEl).find('img');
let imageName = $(linkEl).text().trim();
if (!imageName && img.length) {
imageName = img.attr('alt') || '';
}
if (!imageName) {
const urlMatch = href.match(/evidence%2F([^&]+)/);
imageName = urlMatch ? decodeURIComponent(urlMatch[1]) : `image-${images.length + 1}.png`;
}
const extMatch = imageName.match(/\.(png|jpg|jpeg|gif|svg|webp)$/i);
const extension = extMatch ? extMatch[0] : '.png';
imageName = imageName.replace(/\.[^.]+$/, '') + extension;
imageName = imageName.replace(/[^a-zA-Z0-9.-]/g, '_');
let imageUrl = href;
if (!imageUrl.startsWith('http')) {
imageUrl = BASE_URL + imageUrl;
}
images.push({
name: imageName,
url: imageUrl,
alt: img.length ? (img.attr('alt') || '') : '',
});
});
return { title, metadata, sections, images };
}
// --- Image handling ---
function isBrokenImage(filePath) {
if (!existsSync(filePath)) return false;
const buf = readFileSync(filePath);
const start = buf.toString('utf8', 0, 100).trimStart();
return start.startsWith('<') || start.startsWith('<!');
}
function downloadImage(imageUrl, outputPath, cookie) {
try {
curlDownload(imageUrl, outputPath, cookie);
const buf = readFileSync(outputPath);
const start = buf.toString('utf8', 0, 100).trimStart();
if (start.startsWith('<') || start.startsWith('<!')) {
logError(`Got HTML instead of image for ${imageUrl} - session may have expired`);
return false;
}
return true;
} catch (error) {
logError(`Failed to download image ${imageUrl}: ${error.message}`);
return false;
}
}
function downloadImagesForIssue(issueId, content, cookie) {
const issueDir = join(ISSUES_DIR, issueId.toString());
const results = [];
content.images.forEach((image) => {
const safeName = image.name.replace(/[^a-zA-Z0-9.-]/g, '_');
const imagePath = join(issueDir, safeName);
if (downloadImage(image.url, imagePath, cookie)) {
results.push({ originalName: image.name, localPath: safeName, alt: image.alt });
}
});
return results;
}
// --- Markdown generation ---
function createMarkdownFile(issueId, content, cookie) {
const issueDir = join(ISSUES_DIR, issueId.toString());
mkdirSync(issueDir, { recursive: true });
const imagePaths = downloadImagesForIssue(issueId, content, cookie);
const frontmatter = `---
id: ${issueId}
title: "${content.title.replace(/"/g, '\\"')}"
status: ${content.metadata.status}
stage: ${content.metadata.stage}
severity: ${content.metadata.severity}
wcag: ${content.metadata.wcag}
flow: "${content.metadata.flow.replace(/"/g, '\\"')}"
pageUrl: "${content.metadata.pageUrl.replace(/"/g, '\\"')}"
auditDate: "${content.metadata.auditDate}"
---
`;
let markdown = frontmatter + `# ${content.title}\n\n`;
markdown += `## Metadata\n\n`;
markdown += `- **WCAG**: ${content.metadata.wcag}\n`;
markdown += `- **Severity**: ${content.metadata.severity}\n`;
markdown += `- **Status**: ${content.metadata.status}\n`;
markdown += `- **Stage**: ${content.metadata.stage}\n`;
markdown += `- **Flow**: ${content.metadata.flow}\n`;
markdown += `- **Page URL**: ${content.metadata.pageUrl}\n`;
markdown += `- **Audit Date**: ${content.metadata.auditDate}\n\n`;
Object.entries(content.sections).forEach(([sectionName, sectionContent]) => {
markdown += `## ${sectionName}\n\n`;
markdown += sectionContent + '\n\n';
});
if (imagePaths.length > 0) {
markdown += `## Images\n\n`;
imagePaths.forEach(img => {
markdown += `\n\n`;
});
}
const mdPath = join(issueDir, `issue-${issueId}.md`);
writeFileSync(mdPath, markdown);
console.log(` Created ${mdPath}`);
return mdPath;
}
// --- Main flows ---
async function crawlIssues(issueIds, cookie) {
mkdirSync(ISSUES_DIR, { recursive: true });
const progress = loadProgress();
const remaining = issueIds.filter(id => !progress.completed.includes(id));
console.log(`Total issues to crawl: ${issueIds.length}`);
console.log(`Already completed (this run): ${issueIds.length - remaining.length}`);
console.log(`Failed: ${progress.failed.length}`);
console.log(`Remaining: ${remaining.length}\n`);
for (const issueId of remaining) {
try {
progress.current = issueId;
saveProgress(progress);
const content = extractIssueContent(issueId, cookie);
createMarkdownFile(issueId, content, cookie);
progress.completed.push(issueId);
progress.current = null;
saveProgress(progress);
await new Promise(resolve => setTimeout(resolve, 500));
} catch (error) {
progress.failed.push({ id: issueId, error: error.message });
progress.current = null;
saveProgress(progress);
console.error(`Failed to process issue ${issueId}`);
}
}
console.log('\n=== Crawl Complete ===');
console.log(`Completed: ${progress.completed.length}/${issueIds.length}`);
console.log(`Failed: ${progress.failed.length}`);
if (progress.failed.length > 0) {
console.log(`\nFailed issues: ${progress.failed.map(f => f.id).join(', ')}`);
}
}
async function fixImages(cookie) {
mkdirSync(ISSUES_DIR, { recursive: true });
const dirs = readdirSync(ISSUES_DIR, { withFileTypes: true })
.filter(d => d.isDirectory() && /^\d+$/.test(d.name))
.map(d => ({ id: parseInt(d.name, 10), path: join(ISSUES_DIR, d.name) }))
.filter(d => existsSync(join(d.path, `issue-${d.id}.md`)));
let fixed = 0;
for (const { id } of dirs) {
const issueDir = join(ISSUES_DIR, id.toString());
const imageFiles = readdirSync(issueDir)
.filter(f => /\.(jpeg|jpg|png|gif|webp)$/i.test(f))
.map(f => join(issueDir, f));
const broken = imageFiles.filter(isBrokenImage);
if (broken.length === 0) continue;
console.log(`\nFixing ${broken.length} broken image(s) for issue ${id}...`);
try {
const content = extractIssueContent(id, cookie);
downloadImagesForIssue(id, content, cookie);
fixed++;
await new Promise(r => setTimeout(r, 500));
} catch (error) {
logError(`Failed to fix images for issue ${id}: ${error.message}`);
}
}
console.log(`\nFixed images for ${fixed} issue(s).`);
}
// --- Entry point ---
const fixMode = process.argv.includes('--fix-images');
const fromCsv = process.argv.includes('--from-csv');
const idsFile = getIdsFileArg();
const missingOnly = process.argv.includes('--missing-only');
const dryRun = process.argv.includes('--dry-run');
const discoverNew = process.argv.includes('--discover-new');
const cookie = getCookieArg();
function printCookieUsage() {
console.error('Missing --cookie flag. Usage:');
console.error(' node crawl-issues.js --cookie "csrftoken=...; sessionid=..."');
console.error(' node crawl-issues.js --discover-new --cookie "csrftoken=...; sessionid=..."');
console.error('');
console.error('Get cookies from browser: open app.workback.ai, DevTools → Application → Cookies,');
console.error('or copy from a curl command (Network tab → Copy as cURL).');
}
async function main() {
if (discoverNew && (fromCsv || idsFile)) {
console.warn('Warning: --discover-new ignores --from-csv and --ids-file.');
}
if (fixMode) {
if (!cookie) {
printCookieUsage();
process.exit(1);
}
await fixImages(cookie);
return;
}
let issueIds;
if (discoverNew) {
if (!cookie) {
printCookieUsage();
process.exit(1);
}
const discoverPages = getIntArg('--discover-pages', DEFAULT_DISCOVER_PAGES);
const stopAfterStalePages = getIntArg('--discover-stop-after-stale-pages', DEFAULT_STOP_AFTER_STALE_PAGES);
issueIds = discoverNewIssueIds(cookie, discoverPages, stopAfterStalePages);
} else {
issueIds = getIdsToCrawl(fromCsv, idsFile, missingOnly);
}
if (issueIds.length === 0) {
console.log('No issues to crawl. All issues from the source already exist in issues/.');
return;
}
if (dryRun) {
console.log(`Would crawl ${issueIds.length} issue(s):`);
console.log(issueIds.join(', '));
return;
}
if (!cookie) {
printCookieUsage();
process.exit(1);
}
await crawlIssues(issueIds, cookie);
}
main().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});