Skip to content

Commit

Permalink
#1603 Only get missing logins
Browse files Browse the repository at this point in the history
  • Loading branch information
thekingofcity committed Jul 19, 2024
1 parent f316de0 commit 74b946d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions scripts/loginbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import { resolve } from 'path';

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

const getLoginsByType = async type => {
const getLoginsByType = async (type, cachedLogins) => {
// const data = JSON.parse(await readFile(`${type}.json`, 'utf-8'));
const data = JSON.parse(await readFile(resolve('..', 'public', 'resources', `${type}.json`), 'utf-8'));
const ids = new Set(
Object.values(data)
.map(_ => _.contributors)
.flat()
);
const ret = {};
const ret = cachedLogins[type];
type = type === 'real_world' ? 'realWorld' : type; // real_world -> realWorld
for (const id of ids) {
if (id in cachedLogins[type]) {
continue;
}
const rep = await (await fetch(`https://api.github.com/user/${id}`)).json();
ret[id] = rep.login;
console.log(`login for id: ${id} is ${ret[id]}`);
Expand All @@ -21,18 +25,18 @@ const getLoginsByType = async type => {
return ret;
};

export const getLogins = async () => {
export const makeLogins = async () => {
const loginPath = resolve('..', 'public', 'resources', 'logins.json');
const cachedLogins = JSON.parse(await readFile(loginPath, 'utf-8'));

const logins = {
realWorld: await getLoginsByType('real_world'),
fantasy: await getLoginsByType('fantasy'),
realWorld: await getLoginsByType('real_world', cachedLogins),
fantasy: await getLoginsByType('fantasy', cachedLogins),
};

// await writeFile('logins.json', JSON.stringify(logins, null, 4), {
// encoding: 'utf-8',
// });
await writeFile(resolve('..', 'public', 'resources', 'logins.json'), JSON.stringify(logins, null, 4), {
await writeFile(loginPath, JSON.stringify(logins, null, 4), {
encoding: 'utf-8',
});
};

await getLogins();
await makeLogins();

0 comments on commit 74b946d

Please sign in to comment.