From 03adc50206e4c9f0f7f9981ee3bfdab140a9fd29 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Thu, 30 Jan 2025 08:20:17 -0500 Subject: [PATCH] more stuff --- rank.js | 11 +++++++---- darflen.js => site.js | 37 ++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 17 deletions(-) rename darflen.js => site.js (53%) diff --git a/rank.js b/rank.js index 6ecf6fd..dabba60 100644 --- a/rank.js +++ b/rank.js @@ -5,7 +5,7 @@ function rankCalc(result, iterations = 10) { let fng = {}; let fnc = {}; let frs = {}; - let msum_old = 0; + let msum_old = 0.001; let pr = {}; for (let unn in result) { @@ -44,12 +44,15 @@ function rankCalc(result, iterations = 10) { for (let una in result) { pr[una] = 0; matrixe[una] = []; - if (frs[una].length == 0) continue; + if (frs[una].length == 0) { + matrixe[una] = structuredClone(matrixf[una]); // probably not efficient + continue; + } for (let unb in result) { let prb = prold[unb]; - if (prb < 1 / 1e4 || fnc[unb] == 0) { - //msum += matrixe[una][unb]; + if (prb < 1 / 1e9 || fnc[unb] == 0) { + matrixe[una][unb] = matrixf[una][unb]; continue; } matrixe[una][unb] = 0.03; diff --git a/darflen.js b/site.js similarity index 53% rename from darflen.js rename to site.js index 6cf0c1a..9c387be 100644 --- a/darflen.js +++ b/site.js @@ -2,23 +2,36 @@ import { writeFile } from "fs/promises"; import { rankCalc } from "./rank.js"; -(async function () { +let cache = {}; + +async function siteCollector(user, path) { let users = []; - let i = 0; - while (true) { - let h1 = await fetch(`https://api.darflen.com/users/paradock/followers/${i}`) - let j1 = await h1.json(); + let p = `https://api.darflen.com/users/${user}/${path}/${i}`; + let j1 = cache[p] + if (!j1) { + let h1 = await fetch(p); + j1 = await h1.json(); + } + cache[p] = j1; - let users2 = j1.followers.map(x => x.profile.username); + let users2 = j1[path].map(x => x.profile.username); users = [...users, ...users2]; if (users2.length == 0) break; i++; + + console.log(`User ${user} has ${i} pages calculated`); } + return users; +} + +(async function () { + let users = await siteCollector('paradock','followers'); + let data = {}; let p = []; for (let u of users) { @@ -27,17 +40,15 @@ import { rankCalc } from "./rank.js"; p = []; } p.push((async function () { - let h1 = await fetch(`https://api.darflen.com/users/${u}/followers`) - let j1 = await h1.json(); + let j1 = await siteCollector(u,'followers'); - let h2 = await fetch(`https://api.darflen.com/users/${u}/following`) - let j2 = await h2.json(); + let j2 = await siteCollector(u,'following'); data[u] = { - followers: j1.followers.map(x => x.profile.username), - following: j2.following.map(x => x.profile.username) + followers: j1, + following: j2, } - console.log(`User ${u} calculated`); + console.log(`User ${u} fully calculated`); })()) }