Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.49 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. // these monster IDs (we think!) don't drop anything, so we can skip them
  30. var missing = "2 8 21 23 32 35 38 39 47 48 52 53 55 58 59 61 74 78 81 86 87 89 90 92 95 99 103 105 107 108 109 110 112 114 115 117 118 119 125 128 133 138 139 141 158 159 168 169 173 175 178 192 479 493 533 749 839 840 862 906 931 1019 1020 1044 1045 1046 1105 1106 1107 1108 1110 1111 1192 1193 1203 1219 1227 1229 1230 1231 1232 1233 1234 1235 1239 1241 1265 1319 1329 1404 1582 1585 1586 1587 1588 1589 1590 1591 1593 1594 1600 1601 1603 1605 1606 1608 1609 1616 1620 1623 1624 1626 1627 1628 1631 1632 1633 1635 1636 1637 1639 1644 1646 1677 1678 1691 1751 1752 1758 1828 1829 1831 1903 1976 1993 1994 2033 2050 2051 2052 2053 2054 2069 2070 2071 2072 2074 2136 2245 2249 2251 2313 2314 2315 2359 2361 2362 2452 2455 2456 2457 2682 2740 2742 2744 2803 2804 2805 2806 2808 2850 2884 2887 2888 2889 2892 2894 2896 3026 3027 3028 3049 3070 3072 3073 3153 3228 3229 3230 3231 3261 3309 3346 3348 3376 3406 3419 3449 3450 3451 3484 3673 3675 3707 3783 3808 3814 3815 3816 3939 4265 4271 4273 4291 4292 4347 4349 4351 4352 4353 4354 4356 4357 4381 4383 4388 4389 4390 4400 4401 4408 4415 4479 4492 4531 4665 4666 4668 4669 4670 4671 4672 4681 4683 4685 4688 4689 4690 4691 4692 4693 4733 4796 4868 4870 4910 4920 4921 4924 4926 4927 4935 5044 5045 5048 5097 5144 5204 5250 5285 5305 5310 5312 5319 5321 5324 5334 5335 5336 5337 5339 5340 5355 5356 5370 5372 5373 5374 5381 5386 5393 5413 5414 5417 5418 5422 5521 5522 5523 5527 5529 5561 5584 5750 5852 5861 5919 5994 5995 6006 6007 6008 6010 6012 6014 6015 6017 6019 6021 6022 6023 6024 6043 6046 6047 6048 6049 6051 6078 6079 6080 6115 6116 6142 6143 6144 6145 6159 6198 6236 6272 6273 6274 6275 6279 6280 6306 6308 6324 6326 6347 6359 6363 6364 6367 6368 6376 6377 6468 6469 6470 6471 6472 6473 6514 6552 6710 6750 6751 6761 6762 6763 6771 6773 6774 6776 6777 6778 6779 7169 7291 7398 7643 7797 7798 7799 7800 7916 7917 7918 7919 7920 7940 8125 8285 8350 8351 8357 8658 8763 8834 8871 8872 8993 9066 9744 9773 9776 9910 9928 9964 10019 10020 10039 10069 10070 10147 10150 10151 10420 10508 11232 11234 11238 11240 11241 11713 11734 11744 11747 11753 11758 11761 11769 11788 11804 11862 11866 11887 11888 11889 11890 11891 11892 11893 11894 11906 11911 11912 11920 11958 11965 12014 12017 12025 12059 12062 12068 12353 12355 12357 12362 12363 12364 12365 12366 12370 12371 12589 12652 12690 12855 12856 13095 13100 13229 13231 13246 13250 13465 13466 13467 13468 13470 13471 13472 13473 13474 13475 13476 13477 13478 13479 13480 13481 13744 13745 13746 13747 13748 13749 14122 14124 14136 14139 14298 14299 14300 14492 14690 14694 14939 15199 15202 15204 15208 15211 15214 15222 15297 15302 15303 15305 15306 15307 15308 15309 15310 15362 15388 15389 15390 15391 15396 15397 15398 15399 15400 15401 15599 16693 16694 16695 16696 16697 16698 16699 16703 16726 16732 16739 16740 16741 16742 16743 16744 16745 16746 16749 16750 16751 16752 16753 16754 16755 16756 16757 16759 16760 16761 16762 16763 16764 16768 16769 16770 16771 16772 16773 16774 16775 16778 16779 16780 16781 16782 16783 16784 16785 16786 16788 16789 16790 16791 16792 16793 16794 16796 16798 16799 16800 16801 16802 16803 16804 16805 16806 16808 16809 16810 16811 16812 16813 16814 16815 16816 16817 16818 16819 16820 16821 16823 16859 16860 16984 16988 17068 17150 17160 17273 17280 17393 18083 18091 18092 18093 18094 18933 19088 19145 19147 19148 19149 19358 19359 19361 19362 19363 19364 19365 19366 19874 20099 20367 20368 20369 20378 20630 20723 20724 20725 20726 20727 20728 20729 20730 20742 20744 20745 20803 20817 20885 20886 20891 20892 20894 20898 20900 20906 20910 20912 20913 20915 20917 20918 20920 20921 20925 20926 20927 21143 21202 21208 21336 21337 21361 21363 21389 21413 21496 21500 21501 21982 21992 21995 22001 22177 22178 22179 22180 22181 22182 22184 22185 22186 22187 22188 22189 22190 22191 22192 22193 22194 22195 22196 22197 22198 22235 22236 22256 22296 22452 22474 22475 22476 22482 22483 22484 22493 22494 22495 22524 22569 22573 22585 22586 22614 22721 22753 22754 22786 22908 22909 22910 23046 23048 23049 23050 23052 23053 23059 23067 23068 23363 23366 23391 23413 23414 23415 23416 23417 23424 23425 23681 23832 23834 23845 23857 24005 24007 24008 24011 24012 24013 24016 24018 24202 24205 24207 24209 24211 24213 24215 24217 24219 24221 24223 24225 24227 24229 24231 24233 24235 24237 24239 24241 24243 24249 24251 24253 24255 24257 24263 24273 24275 24277 24279 24281 24283 24306 24308 24310 24365 24369 24594 24595 24616 24677 24678 24679 24680 24765 24766 24767 24768 25157 25158".split(" ");
  31.  
  32. var totalMonsters = undefined;
  33. var visitedMonsters = 0;
  34.  
  35. function postData(url, data, username) {
  36. // this is my server's URL. It only posts data from getDrops and getKills.
  37. var postUrl = "https://cookmeplox.pythonanywhere.com/runemetricslogger/";
  38. $.post(postUrl, data + "&&&" + username + "&&&" + url + "^^^" + metadata);
  39. }
  40.  
  41. // get data from RuneMetrics, retrying on failure, and stopping if session ends.
  42. function safeGet(url, callback) {
  43. if (sessionEnded) {
  44. return;
  45. }
  46. $.ajax(url, {
  47. success: callback,
  48. error: function(xhr) {
  49. if (sessionEnded) {
  50. return;
  51. }
  52. if (xhr.status === 0) {
  53. console.error("Uh oh! We think your session ended prematurely. Try refreshing the page and running again. If this persists, contact Cook Me Plox.");
  54. sessionEnded = true;
  55. } else {
  56. if (this.retries > 0) {
  57. console.log("Failed to GET url " + url + " -- retrying (" + this.retries + " left)");
  58. this.retries--;
  59. $.ajax(this);
  60. return;
  61. } else {
  62. console.error("Failed to GET url " + url + " -- retries exhausted.");
  63. }
  64. }
  65. },
  66. retries: 3
  67. });
  68. }
  69.  
  70. function getDrops(start, end, id) {
  71. var url = "https://apps.runescape.com/runemetrics/aggregations/npc/drop-log/range/day?&start=" + start + "&end=" + end + "&id=" + id;
  72. safeGet(url, function(data) {
  73. visitedMonsters++;
  74. console.log("Got drops for monster #" + id + "; " + visitedMonsters + "/" + totalMonsters + " done");
  75. postData(url, JSON.stringify(data), username);
  76. });
  77. }
  78.  
  79. function getKills(start, end) {
  80. metadata.runID = Math.random();
  81. visitedMonsters = 0;
  82. var url = "https://apps.runescape.com/runemetrics/aggregations/npc/kill/range/day?&start=" + start + "&end=" + end;
  83. safeGet(url, function(data) {
  84. console.log("Got kills");
  85. postData(url, JSON.stringify(data), username);
  86. var kills = data;
  87. var aggKills = {};
  88. kills.monsterKills.forEach(function(day) {
  89. Object.keys(day).forEach(function(hourKey) {
  90. if (hourKey == "day") {
  91. return;
  92. }
  93. Object.keys(day[hourKey]).forEach(function(idKey) {
  94. var thisKills = day[hourKey][idKey].kills;
  95. aggKills[idKey] = aggKills.hasOwnProperty(idKey) ? (aggKills[idKey] + thisKills) : thisKills;
  96. });
  97. });
  98. });
  99.  
  100. var flatKills = [];
  101. Object.keys(aggKills).forEach(function(key) {
  102. flatKills.push([key, aggKills[key]]);
  103. });
  104.  
  105. flatKills.sort(function(a, b) {
  106. return b[1] - a[1];
  107. });
  108. if (skip) {
  109. flatKills = flatKills.filter(function(key) {
  110. return missing.indexOf(key[0]) !== -1;
  111. });
  112. }
  113. if (useBatch) {
  114. flatKills = flatKills.filter(function(key) {
  115. return parseInt(key[0]) % totalBatches === currentBatch;
  116. });
  117. }
  118. totalMonsters = flatKills.length;
  119. flatKills.forEach(function(elt, i) {
  120. var id = elt[0];
  121. getDrops(start, end, id);
  122. });
  123. });
  124. }
  125.  
  126. getKills(start, end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement