Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. // USAGE INSTRUCTIONS:
  2. // Go to https://apps.runescape.com/runemetrics/app/pvm-kills (logging in, if needed)
  3. // Open up the JavaScript console in your browser
  4. // Paste this code into the console and press enter
  5. // Please report any errors or bugs to Cook Me Plox
  6.  
  7. // change currentBatch to be in [0 ... totalBatches-1]
  8. var currentBatch = 0;
  9. var totalBatches = 1;
  10.  
  11. // start and end times in Unix millis
  12. var start = 1420294400000;
  13. var end = 1620899199999;
  14.  
  15. // get your username
  16. var avatar = $("#a-header-avatar").attr("alt");
  17. var username = avatar.substr(0, avatar.length - 7);
  18.  
  19. var versionID = "1.0/custom";
  20. // whether to skip monsters we think drop nothing
  21. var skip = true;
  22. // whether to batch scraping into separate runs, if you time out frequently
  23. var useBatch = true;
  24.  
  25. var sessionEnded = false;
  26.  
  27. var metadata = JSON.stringify({"runID": Math.random(), "versionID": versionID, "skip": skip, "currentBatch": currentBatch, "totalBatches": totalBatches});
  28.  
  29. var missing = "1 2 23 52 61 62 64 67 74 81 86 90 103 112 175 179 191 196 298 357 504 505 752 799 830 1019 1097 1104 1105 1107 1108 1109 1110 1111 1196 1228 1231 1234 1235 1263 1317 1318 1321 1329 1330 1404 1588 1601 1602 1637 1640 1642 1648 1649 1650 1654 1655 1656 1657 1828 1874 1962 2091 2236 2314 2442 2600 2742 2744 2804 2806 2880 3065 3073 3153 3242 3244 3256 3261 3263 3264 3348 3451 3532 3533 3594 3673 3940 4272 4345 4356 4387 4392 4408 4410 4411 4412 4479 4482 4486 4487 4488 4491 4665 4706 4926 4927 5307 5308 5309 5313 5322 5334 5335 5348 5356 5357 5358 5362 5365 5369 5370 5371 5522 5829 6006 6014 6015 6024 6051 6323 6325 6326 6328 6329 6365 6379 6707 6710 6777 7078 7079 7080 7081 7158 7492 7797 7798 7799 7800 7882 7883 7916 7917 7918 7919 7920 7925 8314 8323 8352 8363 8563 8565 8774 8776 8778 8779 8782 8993 9622 9751 9928 9990 10020 10071 10150 10508 10805 11862 11868 11940 12036 12044 12076 12081 12364 12539 12680 13248 14297 14838 14849 15213 15954 15958 16210 16211 16264 16740 16755 16761 16770 16790 16800 16809 17074 17077 17079 17094 17139 17145 17146 17150 17153 17159 17273 17280 18083 20906 20921 21137 21156 21208 21983 22167 22256 22296 22485 22891 22935 23046 23048 23049 23050 23052 23053 23059 23145 23362 23364 23365 23366 23391 23413 23425 23800 23805 24008 24016 24017 24018 24019 24170 24831".split(" ");
  30.  
  31. var totalMonsters = undefined;
  32. var visitedMonsters = 0;
  33.  
  34. function postData(url, data, username) {
  35. // this is my server's URL. It only posts data from getDrops and getKills.
  36. var postUrl = "https://cookmeplox.pythonanywhere.com/runemetricslogger/";
  37. $.post(postUrl, data + "&&&" + username + "&&&" + url + "^^^" + metadata);
  38. }
  39.  
  40. // get data from RuneMetrics, retrying on failure, and stopping if session ends.
  41. function safeGet(url, callback) {
  42. if (sessionEnded) {
  43. return;
  44. }
  45. $.ajax(url, {
  46. success: callback,
  47. error: function(xhr) {
  48. if (sessionEnded) {
  49. return;
  50. }
  51. if (xhr.status === 0) {
  52. console.error("Uh oh! We think your session ended prematurely. Try refreshing the page and running again. If this persists, contact Cook Me Plox.");
  53. sessionEnded = true;
  54. } else {
  55. if (this.retries > 0) {
  56. console.log("Failed to GET url " + url + " -- retrying (" + this.retries + " left)");
  57. this.retries--;
  58. $.ajax(this);
  59. return;
  60. } else {
  61. console.error("Failed to GET url " + url + " -- retries exhausted.");
  62. }
  63. }
  64. },
  65. retries: 3
  66. });
  67. }
  68.  
  69. function getDrops(start, end, id) {
  70. var url = "https://apps.runescape.com/runemetrics/aggregations/npc/drop-log/range/day?&start=" + start + "&end=" + end + "&id=" + id;
  71. safeGet(url, function(data) {
  72. visitedMonsters++;
  73. console.log("Got drops for monster #" + id + "; " + visitedMonsters + "/" + totalMonsters + " done");
  74. postData(url, JSON.stringify(data), username);
  75. });
  76. }
  77.  
  78. function getKills(start, end) {
  79. metadata.runID = Math.random();
  80. visitedMonsters = 0;
  81. var url = "https://apps.runescape.com/runemetrics/aggregations/npc/kill/range/day?&start=" + start + "&end=" + end;
  82. safeGet(url, function(data) {
  83. console.log("Got kills");
  84. postData(url, JSON.stringify(data), username);
  85. var kills = data;
  86. var aggKills = {};
  87. kills.monsterKills.forEach(function(day) {
  88. Object.keys(day).forEach(function(hourKey) {
  89. if (hourKey == "day") {
  90. return;
  91. }
  92. Object.keys(day[hourKey]).forEach(function(idKey) {
  93. var thisKills = day[hourKey][idKey].kills;
  94. aggKills[idKey] = aggKills.hasOwnProperty(idKey) ? (aggKills[idKey] + thisKills) : thisKills;
  95. });
  96. });
  97. });
  98.  
  99. var flatKills = [];
  100. Object.keys(aggKills).forEach(function(key) {
  101. flatKills.push([key, aggKills[key]]);
  102. });
  103.  
  104. flatKills.sort(function(a, b) {
  105. return b[1] - a[1];
  106. });
  107. if (skip) {
  108. flatKills = flatKills.filter(function(key) {
  109. return missing.indexOf(key[0]) !== -1;
  110. });
  111. }
  112. if (useBatch) {
  113. flatKills = flatKills.filter(function(key) {
  114. return parseInt(key[0]) % totalBatches === currentBatch;
  115. });
  116. }
  117. totalMonsters = flatKills.length;
  118. flatKills.forEach(function(elt, i) {
  119. var id = elt[0];
  120. getDrops(start, end, id);
  121. });
  122. });
  123. }
  124.  
  125. getKills(start, end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement