Skip to content

Commit

Permalink
accept Uri as input to check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jul 12, 2013
1 parent d77b5bd commit 7c64d10
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions grader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ References:
- https://developer.mozilla.org/en-US/docs/JSON#JSON_in_Firefox_2
*/

var sys = require('util'),
rest = require('restler');

var fs = require('fs');
var program = require('commander');
var cheerio = require('cheerio');
Expand All @@ -29,15 +32,30 @@ var CHECKSFILE_DEFAULT = "checks.json";

var assertFileExists = function(infile) {
var instr = infile.toString();
if(!fs.existsSync(instr)) {
/* if(!fs.existsSync(instr)) {
console.log("%s does not exist. Exiting.", instr);
process.exit(1); // http://nodejs.org/api/process.html#process_process_exit_code
}
*/
return instr;
};

var cheerioHtmlFile = function(htmlfile) {
return cheerio.load(fs.readFileSync(htmlfile));
var options = {
method: "GET"};

var data = '';
rest.get(htmlfile, options).
on('complete', function(data, response){
console.log('Status: ' + response.statusCode);

//return cheerio.load(data);

});

return cheerio.load(data);

//return cheerio.load(fs.readFileSync(htmlfile));
};

var loadChecks = function(checksfile) {
Expand All @@ -64,9 +82,9 @@ var clone = function(fn) {
if(require.main == module) {
program
.option('-c, --checks <check_file>', 'Path to checks.json', clone(assertFileExists), CHECKSFILE_DEFAULT)
.option('-f, --file <html_file>', 'Path to index.html', clone(assertFileExists), HTMLFILE_DEFAULT)
.option('-u, --uri <html_file>', 'Path to yoour URI', clone(assertFileExists), HTMLFILE_DEFAULT)
.parse(process.argv);
var checkJson = checkHtmlFile(program.file, program.checks);
var checkJson = checkHtmlFile(program.uri, program.checks);
var outJson = JSON.stringify(checkJson, null, 4);
console.log(outJson);
} else {
Expand Down

0 comments on commit 7c64d10

Please sign in to comment.