-
Notifications
You must be signed in to change notification settings - Fork 1
/
jobs.mjs
78 lines (67 loc) · 1.68 KB
/
jobs.mjs
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
import { parse } from 'csv-parse/sync';
import { writeFileSync } from 'fs';
import { resolve } from 'path';
import fetch from 'node-fetch';
import slugify from 'slugify';
const url =
'https://docs.google.com/spreadsheets/d/e/2PACX-1vSW2DHW7Optt8J5aRYmYyHF3Vkx5ixbgnX8ZVcDBXNeE_0WRkcigY3PYVbQUfpvj_yrtNdAvK4jjbW3/pub?output=csv';
async function main() {
const res = await fetch(url);
const text = await res.text();
const records = parse(text, {
columns: [
'timestamp',
'email',
'title',
'description',
'city',
'country',
'type',
'company',
'url',
'from',
'promote',
'salary',
'approved',
],
skip_empty_lines: true,
from: 2,
});
writeFileSync(
resolve('src', '_data', 'jobs.json'),
JSON.stringify(
records
.map((_) => {
if (_.from) {
// _.from = new Date(_.from);
} else {
_.from = _.timestamp;
}
_.type = _.type.split(', ');
_.slug = slugify(
`${_.company} - ${_.title} ${new Date(_.from).getFullYear()}-${
new Date(_.from).getMonth() + 1
}`,
{ lower: true }
);
if (!_.approved || _.approved.toLowerCase() === 'n') {
_.approved = false;
} else {
_.approved = true;
}
if (!_.url.startsWith('http')) {
_.url = 'https://' + _.url;
}
return _;
})
.filter((_) => {
if (!_.approved) {
return false;
}
return true;
// also if expired
})
)
);
}
main().catch((E) => console.log(E));