-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackpop.js
64 lines (61 loc) · 1.93 KB
/
backpop.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import fetch from 'node-fetch';
import fs from 'fs';
const url =
'https://api.github.com/repos/jason-tung/leetcode/commits?per_page=100&page=';
const main = async () => {
let commits = [];
for (let i = 1; i <= 3; i++) {
const iurl = `${url}${i}`;
console.log('fetching from', iurl);
const d = await (
await fetch(iurl, {
headers: { Authorization: `${process.env.GHTOKEN}` },
})
).json();
// console.log(d);
d.forEach((k) => commits.push(k));
console.log(commits.length);
}
commits = commits.filter(
(k) =>
k.commit.message.startsWith(
'[jasbob-leetcode-bot] automated upload of <'
) && !k.commit.message.includes('--')
);
console.log(commits.length);
commits = commits.map((d) => {
const title = d.commit.message.replace(
'[jasbob-leetcode-bot] automated upload of ',
''
);
const split = title.split(' ');
const difficulty = split[0].replace(/[<>]/g, '');
const formattedTitle = split[1];
const splitName = formattedTitle.split('-');
const problemNumber = splitName[0];
const problemName = splitName
.slice(1)
.join(' ')
.replace(/^\w|\s\w/g, (x) => x.toUpperCase());
return {
timestamp: d.commit.committer.date,
formattedTitle,
problemNumber,
problemName,
difficulty,
};
});
commits = commits.filter((k) => {
return (
!/[^a-zA-Z0-9\-]/.test(k.formattedTitle) &&
k.problemNumber !== '99999'
);
});
commits = commits.sort(
(a, b) => new Date(a.timestamp) - new Date(b.timestamp)
);
console.log(commits.length);
console.log(commits.at(0));
fs.writeFileSync('backpop.json', JSON.stringify(commits, undefined, 4));
};
main();