Permalink
Browse files

accept Uri as input to check

  • Loading branch information...
1 parent d77b5bd commit 7c64d100c172a8c60e25be241f3a1925847bd70d Ubuntu committed Jul 12, 2013
Showing with 22 additions and 4 deletions.
  1. +22 −4 grader.js
View
@@ -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');
@@ -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) {
@@ -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 {

0 comments on commit 7c64d10

Please sign in to comment.