-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·47 lines (34 loc) · 1.06 KB
/
index.js
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
const Sheet = require('./sheet');
const fetch = require('node-fetch');
async function scrapePage(i) {
const res = await fetch(`https://jobs.github.com/positions.json?page=${i}&search=code`);
const json = await res.json();
const rows = json.map(job => {
return {
company: job.company,
title: job.title,
location: job.location,
date: job.created_at,
url: job.url
}
});
return rows;
}
(async function () {
let i = 1;
let rows = [];
while (true) {
const newRows = await scrapePage(i);
if (newRows.length === 0) break;
rows = [...rows, ...newRows]; // Similar to rows = rows.concat(newRows);
i++;
}
let sortedByDate = rows.sort((a, b) => {
return new Date(b.date) - new Date(a.date);
});
let searchQuery = 'frontend';
let filteredData = sortedByDate.filter(data => data.title.toLowerCase().includes(searchQuery));
const sheet = new Sheet();
await sheet.load();
await sheet.addRows(filteredData);
})();