untitled notebook

node v18.11.0
version: master
endpointsharetweet
// modul http const axios = require('axios'); // modul rng const MersenneTwister = require('mersenne-twister'); const draw = async (id, cutoff) => { // generowanie danych autoryzacji niezalogowanego uzytkownika // klucz i sekret prawdopodobnie sa kluczami api frontu wykop.pl const { data: { data: { token } } } = await axios.post( 'https://wykop.pl/api/v3/auth', { data: { key: 'w53947240748', secret: 'd537d9e0a7adc1510842059ae5316419', }, }, ); console.log('a zalogowalem sie'); // pobierz glosy z wpisu const { data: { data: votes } } = await axios.get( `https://wykop.pl/api/v3/entries/${id}/votes`, { headers: { Authorization: `Bearer ${token}` }, }, ); console.log(`pobralem se ${votes.length} glosow.`); // zaseedujemy rng id posta // bedzie fair const rng = new MersenneTwister(id); // losujemy wygranego const winner = votes[Math.floor(rng.random() * Math.min(cutoff, votes.length))]; console.log(`mamy zwyciezce: ${winner.username}!`); return winner; }; // id posta const id = '70407121'; // z chwila losowania jest 1890 glosow // nie ma w api niestety czasu oddania glosu wiec wpisze z reki const cutoff = 1890; // losuj const winner = await draw(id, cutoff); console.log(`wygrywa ${winner.username}`);
Created from: https://runkit.com/docs/endpoint
Loading…

no comments

    sign in to comment