Skip to content

Commit 8f38b48

Browse files
committed
#1603 Only get missing logins
1 parent f316de0 commit 8f38b48

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

scripts/loginbot.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ import { resolve } from 'path';
33

44
const sleep = ms => new Promise(r => setTimeout(r, ms));
55

6-
const getLoginsByType = async type => {
6+
const getLoginsByType = async (type, cachedLogins) => {
77
// const data = JSON.parse(await readFile(`${type}.json`, 'utf-8'));
88
const data = JSON.parse(await readFile(resolve('..', 'public', 'resources', `${type}.json`), 'utf-8'));
99
const ids = new Set(
1010
Object.values(data)
1111
.map(_ => _.contributors)
1212
.flat()
1313
);
14-
const ret = {};
14+
const jsonType = type === 'real_world' ? 'realWorld' : type; // real_world -> realWorld
15+
const ret = cachedLogins[jsonType];
1516
for (const id of ids) {
17+
if (id in cachedLogins[jsonType]) {
18+
continue;
19+
}
1620
const rep = await (await fetch(`https://api.github.com/user/${id}`)).json();
1721
ret[id] = rep.login;
1822
console.log(`login for id: ${id} is ${ret[id]}`);
@@ -21,18 +25,18 @@ const getLoginsByType = async type => {
2125
return ret;
2226
};
2327

24-
export const getLogins = async () => {
28+
export const makeLogins = async () => {
29+
const loginPath = resolve('..', 'public', 'resources', 'logins.json');
30+
const cachedLogins = JSON.parse(await readFile(loginPath, 'utf-8'));
31+
2532
const logins = {
26-
realWorld: await getLoginsByType('real_world'),
27-
fantasy: await getLoginsByType('fantasy'),
33+
realWorld: await getLoginsByType('real_world', cachedLogins),
34+
fantasy: await getLoginsByType('fantasy', cachedLogins),
2835
};
2936

30-
// await writeFile('logins.json', JSON.stringify(logins, null, 4), {
31-
// encoding: 'utf-8',
32-
// });
33-
await writeFile(resolve('..', 'public', 'resources', 'logins.json'), JSON.stringify(logins, null, 4), {
37+
await writeFile(loginPath, JSON.stringify(logins, null, 4), {
3438
encoding: 'utf-8',
3539
});
3640
};
3741

38-
await getLogins();
42+
await makeLogins();

0 commit comments

Comments
 (0)