Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions scripts/sync-leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const path = require("path");

async function fetchData(url) {
try {
const res = await axios.get(url);
const res = await axios.get(url, { timeout: 15000 });
return {
easySolved: res.data.easySolved || 0,
mediumSolved: res.data.mediumSolved || 0,
hardSolved: res.data.hardSolved || 0,
};
} catch (err) {
console.error("API failed to respond: ", err.message);
process.exit(1);
console.error(`API failed for ${url}: ${err.message}`);
return null;
}
}

Expand Down Expand Up @@ -53,6 +53,10 @@ function getFileName(daysAgo) {
console.log("Starting daily fetch...");
for (const user of users) {
const data = await fetchData(baseUrl + user.id);
if (!data) {
console.log(`${user.name}: skipped (API error)`);
continue;
}
const score = data.easySolved + data.mediumSolved * 3 + data.hardSolved * 5;
console.log(`${user.name}:`, data);
overallData.push({
Expand Down
Loading