From 48eb01696d0adc16a66dbf560f5c5771f6ea5428 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sat, 5 Dec 2015 18:44:59 +0000 Subject: Take search query as args --- search.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'search.js') diff --git a/search.js b/search.js index fda4604..e693bad 100644 --- a/search.js +++ b/search.js @@ -12,12 +12,11 @@ var options = { headers: { "Cookie": cookie } }; -var query = 'beans' +var query = process.argv.slice(2,process.argv.length) function result(error, response, body) { if (!error && response.statusCode == 200) { var results = JSON.parse(body); - //console.log(results); search(query, results); } } @@ -25,10 +24,22 @@ function result(error, response, body) { function search(query, json) { json.forEach(function(item) { - if (item.filename.search(query) > 0) { + if (matches(query, item.filename)) { console.log(item.filename); } }); } +function matches(query, filename) { + + var matches = true; + query.forEach(function(word) { + if(filename.search(word) == -1) { + matches = false; + return; + } + }); + return matches; +} + request(options, result); -- cgit v1.2.3