Skip to content

Instantly share code, notes, and snippets.

@Ghostlyr
Last active May 3, 2019 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ghostlyr/8cd78999afcdfc0d03a952d84ad48872 to your computer and use it in GitHub Desktop.
Save Ghostlyr/8cd78999afcdfc0d03a952d84ad48872 to your computer and use it in GitHub Desktop.
var login = 'Archie';
var requests = [];
var page = 1;
var csrftoken = getCookie('csrftoken');
var stats_type = 'current_month';
var has_next = true;
window.getData = function ()
{
$.ajax({
url: '/projects/' + window.project_id + '/statistics/' + stats_type + '/',
type: 'POST',
async: true,
data: {
page: page,
csrfmiddlewaretoken: csrftoken,
},
dataType: 'json',
success: function (data) {
if (data.has_next) {
_(data.voters).each(function (voter) {
requests.push({
nick_minecraft: voter.nick_minecraft.toLowerCase(),
votes_qty: voter.votes_qty,
last_vote_date: voter.last_vote_date,
});
});
page++;
getData();
} else {
countData();
}
},
});
console.log("Collecting data: " + requests.length);
}
window.countData = function () {
var count = 0;
requests.forEach(function (i) {
if (i.nick_minecraft.includes(login.toLowerCase())) {
count += i.votes_qty;
}
});
// console.log(requests);
alert('Total votes from ' + login + ': ' + count);
}
getData();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment