-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.js
More file actions
59 lines (51 loc) · 1.95 KB
/
Copy pathrunner.js
File metadata and controls
59 lines (51 loc) · 1.95 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
import scrapeIndeed from './scraper/indeed.js';
import scrapeRemoteOK from './scraper/remoteok.js';
import scrapeWeWorkRemotely from './scraper/weworkremotely.js';
import saveJobs from './db/saveJobs.js';
import dedupeJobs from './utils/dedupe.js';
import { scrapeJobDetail } from './src/services/jobDetailScraper.service.js';
import pool from './db.js';
(async () => {
const indeedJobs = await scrapeIndeed();
const remoteOKJobs = await scrapeRemoteOK();
const wwrJobs = await scrapeWeWorkRemotely();
const allJobs = [
...indeedJobs,
...remoteOKJobs,
...wwrJobs
];
console.log('Before dedupe:', allJobs.length);
const uniqueJobs = dedupeJobs(allJobs);
console.log('After dedupe:', uniqueJobs.length);
console.log(uniqueJobs);
try {
const { newJobs } = await saveJobs(uniqueJobs);
if (newJobs && newJobs.length > 0) {
console.log(`\n--- Automating JD Scraping for ${newJobs.length} new jobs ---`);
for (const [index, job] of newJobs.entries()) {
console.log(`[${index + 1}/${newJobs.length}] Scraping details for: ${job.link}`);
try {
const scrapeResult = await scrapeJobDetail(job);
if (scrapeResult && scrapeResult.description) {
await pool.query(
'UPDATE jobs SET description = $1 WHERE id = $2',
[scrapeResult.description, job.id]
);
console.log(`✓ Saved description (${scrapeResult.description.length} chars)`);
} else {
console.warn(`! No description found for: ${job.link}`);
}
} catch (scrapeErr) {
console.error(`✗ Scraping failed for ${job.link}:`, scrapeErr.message);
}
}
console.log('--- Automated Scraping Complete ---\n');
}
} catch (err) {
console.error('Runner: failed to save jobs:', err && err.stack ? err.stack : err);
process.exitCode = 1;
} finally {
// Close pool to allow process to exit
await pool.end();
}
})();