Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // USAGE INSTRUCTIONS:
- // Go to https://apps.runescape.com/runemetrics/app/pvm-kills (logging in, if needed)
- // Open up the JavaScript console in your browser
- // Paste this code into the console and press enter
- // Please report any errors or bugs to Cook Me Plox
- // change currentBatch to be in [0 ... totalBatches-1]
- var currentBatch = 0;
- var totalBatches = 1;
- // start and end times in Unix millis
- var start = 1420294400000;
- var end = 1620899199999;
- // get your username
- var avatar = $("#a-header-avatar").attr("alt");
- var username = avatar.substr(0, avatar.length - 7);
- var versionID = "1.0/custom";
- // whether to skip monsters we think drop nothing
- var skip = true;
- // whether to batch scraping into separate runs, if you time out frequently
- var useBatch = true;
- var sessionEnded = false;
- var metadata = JSON.stringify({"runID": Math.random(), "versionID": versionID, "skip": skip, "currentBatch": currentBatch, "totalBatches": totalBatches});
- // these monster IDs (we think!) don't drop anything, so we can skip them
- var missing = "1329".split(" ");
- var totalMonsters = undefined;
- var visitedMonsters = 0;
- function postData(url, data, username) {
- // this is my server's URL. It only posts data from getDrops and getKills.
- var postUrl = "https://cookmeplox.pythonanywhere.com/runemetricslogger/";
- $.post(postUrl, data + "&&&" + username + "&&&" + url + "^^^" + metadata);
- }
- // get data from RuneMetrics, retrying on failure, and stopping if session ends.
- function safeGet(url, callback) {
- if (sessionEnded) {
- return;
- }
- $.ajax(url, {
- success: callback,
- error: function(xhr) {
- if (sessionEnded) {
- return;
- }
- if (xhr.status === 0) {
- console.error("Uh oh! We think your session ended prematurely. Try refreshing the page and running again. If this persists, contact Cook Me Plox.");
- sessionEnded = true;
- } else {
- if (this.retries > 0) {
- console.log("Failed to GET url " + url + " -- retrying (" + this.retries + " left)");
- this.retries--;
- $.ajax(this);
- return;
- } else {
- console.error("Failed to GET url " + url + " -- retries exhausted.");
- }
- }
- },
- retries: 3
- });
- }
- function getDrops(start, end, id) {
- var url = "https://apps.runescape.com/runemetrics/aggregations/npc/drop-log/range/day?&start=" + start + "&end=" + end + "&id=" + id;
- safeGet(url, function(data) {
- visitedMonsters++;
- console.log("Got drops for monster #" + id + "; " + visitedMonsters + "/" + totalMonsters + " done");
- postData(url, JSON.stringify(data), username);
- });
- }
- function getKills(start, end) {
- metadata.runID = Math.random();
- visitedMonsters = 0;
- var url = "https://apps.runescape.com/runemetrics/aggregations/npc/kill/range/day?&start=" + start + "&end=" + end;
- safeGet(url, function(data) {
- console.log("Got kills");
- postData(url, JSON.stringify(data), username);
- var kills = data;
- var aggKills = {};
- kills.monsterKills.forEach(function(day) {
- Object.keys(day).forEach(function(hourKey) {
- if (hourKey == "day") {
- return;
- }
- Object.keys(day[hourKey]).forEach(function(idKey) {
- var thisKills = day[hourKey][idKey].kills;
- aggKills[idKey] = aggKills.hasOwnProperty(idKey) ? (aggKills[idKey] + thisKills) : thisKills;
- });
- });
- });
- var flatKills = [];
- Object.keys(aggKills).forEach(function(key) {
- flatKills.push([key, aggKills[key]]);
- });
- flatKills.sort(function(a, b) {
- return b[1] - a[1];
- });
- if (skip) {
- flatKills = flatKills.filter(function(key) {
- return missing.indexOf(key[0]) !== -1;
- });
- }
- if (useBatch) {
- flatKills = flatKills.filter(function(key) {
- return parseInt(key[0]) % totalBatches === currentBatch;
- });
- }
- totalMonsters = flatKills.length;
- flatKills.forEach(function(elt, i) {
- var id = elt[0];
- getDrops(start, end, id);
- });
- });
- }
- getKills(start, end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement