From fc87711596919ed5697873db1a28562d3594beee Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 7 Sep 2011 15:08:09 -0400 Subject: Allow arbitrary target word. --- wiki-philosophy.js | 14 +++++++++----- 1 file 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(); -- cgit v1.2.3-59-g8ed1b