-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjobs.mjs
100 lines (84 loc) · 2.29 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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,
});
const jobs = records
.map((_) => {
if (!_.from) {
_.from = _.timestamp;
}
_.promote = _.promote === 'Yes';
if (_.from.includes('/')) {
// fix the date to be in the format of yyyy-mm-dd
const [date, time = '00:00:00'] = _.from.split(' ');
const [day, month, year] = date.split('/');
_.from = `${year}-${month}-${day} ${time}`;
}
_.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;
}
// if listing is older than 2 years
if (
new Date(_.from) < new Date(Date.now() - 1000 * 60 * 60 * 24 * 365 * 2)
) {
return false;
}
return true;
// also if expired
})
.sort((a, b) => {
// two part sort, first by promoted and date, then if it's not promoted, just by date
if (a.promote && !b.promote) {
return -1;
} else if (!a.promote && b.promote) {
return 1;
} else {
return new Date(b.from) - new Date(a.from);
}
});
writeFileSync(resolve('src', '_data', 'jobs.json'), JSON.stringify(jobs));
}
main().catch((E) => console.log(E));