aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2011-09-07 15:08:09 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2011-09-07 15:08:09 -0400
commitfc87711596919ed5697873db1a28562d3594beee (patch)
treeb7af4b97a45a1a23ed36edcb8efb47ea90c39f04
parentGive xkcd credit. (diff)
downloadwiki-philosophy-fc87711596919ed5697873db1a28562d3594beee.tar.xz
wiki-philosophy-fc87711596919ed5697873db1a28562d3594beee.zip
Allow arbitrary target word.
-rw-r--r--wiki-philosophy.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/wiki-philosophy.js b/wiki-philosophy.js
index 5cf21b8..ee81810 100644
--- a/wiki-philosophy.js
+++ b/wiki-philosophy.js
@@ -6,9 +6,9 @@
*
*/
-var jsdom = require('jsdom');
-if (process.argv.length == 2)
- return console.error("ERROR: please provide a starting word");
+var jsdom = require("jsdom");
+if (process.argv.length <= 2)
+ return console.error("Usage: " + process.argv[0] + " " + process.argv[1] + " word [target]");
// Keep track of links we've followed to prevent infinite loops.
@@ -19,6 +19,8 @@ var found = false;
var maxParallelRequests = 30;
var currentRequests = 0;
var jQuery = require("fs").readFileSync("./jquery-1.6.2.min.js").toString();
+var targetWord = "Philosophy"
+
function search(page)
{
@@ -71,7 +73,7 @@ function search(page)
}
function appendToQueue(page)
{
- if (page.word == "Philosophy") {
+ if (page.word == targetWord) {
found = true;
done(page);
return;
@@ -85,7 +87,7 @@ function runQueue()
}
function done(page)
{
- console.log("\n\n\n== Philosophy found, sophia achieved! ==\n");
+ console.log("\n== " + targetWord + " found, sophia achieved! ==\n");
// Walk tree backwards to make list.
var list = []
@@ -111,5 +113,7 @@ function stringToWikiurl(string)
}
// Grab the starting word.
+if (process.argv.length == 4)
+ targetWord = process.argv[3][0].toUpperCase() + process.argv[3].slice(1);
appendToQueue({ word: process.argv[2][0].toUpperCase() + process.argv[2].slice(1), parent: null });
runQueue();