Guest User

Untitled

a guest
Nov 22nd, 2016
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. "use strict";
  2.  
  3. var request = require("request");
  4. var readline = require("readline");
  5. var os = require("os");
  6. var fs = require("fs-extra");
  7. var Crawler = require("crawler");
  8. var url = require("url");
  9. var Promise = require("bluebird");
  10.  
  11. const rl = readline.createInterface({
  12. input: process.stdin,
  13. output: process.stdout
  14. });
  15.  
  16. var archivePoint = -1;
  17. var filePath2 = __dirname;
  18.  
  19. var fileCount = 0;
  20.  
  21. var threadSize = 10000;
  22. var threadMaxSize = 1000000; // Not sure atm
  23.  
  24. const redditUrl = "https://reddit.com/r/pizzagate/comments/";
  25. var hotArchiveUrlSearch = "https://www.reddit.com/r/pizzagate/";
  26.  
  27. console.log("Welcome patriot. #PizzaGate is being shut down and American values are being destroyed.");
  28. console.log("We have until 4PM PST to archive everything important");
  29. console.log("Enter either 0-9 based off of the day you were born % 10. So if you were born on the 11th you are a 1. If you are born on the 9th you are a 9. 22nd = 2. 10th = 0");
  30. console.log("Enter all to start archiving everything!");
  31.  
  32. rl.question("Enter `all` or `1-10` without the `:", function(answer) {
  33. if (answer === "all") archivePoint = -1;
  34. else if (Number.isInteger(parseInt(answer)) && (parseInt(answer) <= 9 || parseInt(answer) >= 0)) {
  35. archivePoint = parseInt(answer);
  36. }
  37. rl.question("Enter a absolute file dir path to save to (C:\ or / [linux based] or leave blank [default current dir]): ",
  38. function(filePathIn) {
  39. if (filePathIn) filePath2 = filePathIn;
  40. startArchiving();
  41. });
  42. });
  43.  
  44. function startArchiving() {
  45. console.log("Starting to archive...");
  46. console.log("Creating new directory at: " + filePath2);
  47. var c = new Crawler({
  48. maxConnections: 10,
  49. callback: function(error, result, $) {
  50. new Promise(function(resolve, reject) {
  51. var saveCount = 0;
  52. var fileTrueCount = fileCount;
  53. console.log("visited new index page");
  54.  
  55. fs.ensureDir(filePath2 + "/" + fileTrueCount, function(err) {
  56. console.log("ensuring dir");
  57. fs.outputFile(filePath2 + "/" + fileTrueCount + "/" + "index.html", result.body, function(err) {
  58. console.log("saved: " + filePath2 + "/" + fileTrueCount + "/" + "index.html");
  59.  
  60. $('.comments').each(function(index, a) {
  61. var toQueueUrl = $(a).attr("href");
  62. request(toQueueUrl, function(err, res, body) {
  63. fs.outputFile(filePath2 + "/" + fileTrueCount + "/" + saveCount + ".html", res.body, function(err) {
  64. console.log("saved: " + filePath2 + "/" + fileTrueCount + "/" + saveCount + ".html");
  65. });
  66. saveCount++;
  67. });
  68. });
  69. });
  70. });
  71. resolve($(".next-button a").attr("href"));
  72. }).then(function(url){
  73. fileCount++;
  74. c.queue(url);
  75. });
  76. }
  77. });
  78. c.queue(hotArchiveUrlSearch);
  79. }
Add Comment
Please, Sign In to add comment