Exemple #1
0
var checkUrl = function(result, response) {
    var outJson = {};

    if (result instanceof Error) {
	console.log("Could not connect to %s", program.url);
    } else {
	var fileName = program.url.slice(program.url.search("//"));
	fileName = fileName.replace("/",".");
	console.error("Wrote %s", fileName);
	fs.writeFileSync(fileName, result);

	outJson = checkHtmlFile(fileName, program.checks);
	console.log(outJson);
    }
}
Exemple #2
0
 rest.get(program.url.toString()).on('complete', function(result) {
   if (result instanceof Error) {
     console.log("%s does not exist. Exiting.", program.url.toString());
     process.exit(1); // http://nodejs.org/api/process.html#process_process_exit_code
   } else {
     $ = cheerio.load(result);
     var checks = loadChecks(program.checks).sort();
     var out = {};
     for(var ii in checks) {
       var present = $(checks[ii]).length > 0;
       out[checks[ii]] = present;
     }
     var outJson = JSON.stringify(out, null, 4);
     console.log(outJson);        
   }
 });
Exemple #3
0
var outjson = JSON.stringify(out, null, 4);
console.log(outjson);
	}
    });

};

var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

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, --url <url>', 'Url to download the html from')
	.parse(process.argv);

    if (program.url){
	checkJson = checkUrl(program.url.toString(), program.checks);
    } else {
	var checkJson = checkHtmlFile(program.file, program.checks);
	var outJson = JSON.stringify(checkJson, null, 4);
	console.log(outJson);
    }
} else {
    exports.checkHtmlFile = checkHtmlFile;
}
Exemple #4
0
    return fn.bind({});
};

if(require.main == module) {
    program
        .option('-c, --checks [check_file]', 'Path to JSON file for list of checking. Default to checks.json', clone(assertFileExists), CHECKSFILE_DEFAULT)
        .option('-f, --file <html_file>', 'Path to HTML file to be checked.', clone(assertFileExists))
        .option('-u, --url <url_address>', 'URL Address to be checked.')
        .parse(process.argv);
    if (program.file !== undefined) {
      var checkJson = checkHtmlFile(program.file, program.checks);
      var outJson = JSON.stringify(checkJson, null, 4);
      console.log(outJson);
    }
    if (program.url !== undefined) {
      rest.get(program.url.toString()).on('complete', function(result) {
        if (result instanceof Error) {
          console.log("%s does not exist. Exiting.", program.url.toString());
          process.exit(1); // http://nodejs.org/api/process.html#process_process_exit_code
        } else {
          $ = cheerio.load(result);
          var checks = loadChecks(program.checks).sort();
          var out = {};
          for(var ii in checks) {
            var present = $(checks[ii]).length > 0;
            out[checks[ii]] = present;
          }
          var outJson = JSON.stringify(out, null, 4);
          console.log(outJson);        
        }
      });
Exemple #5
0
var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

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, --url <url_link>', 'Url path to index.htm')
	.parse(process.argv);

		if (program.url) {
			var url = program.url.toString();
			rest.get(url).on('complete', function(result){
				$ = cheerio.load(result);
				//console.log(cheerio.load(result));
				console.log(url);

				var checks = loadChecks(program.checks).sort();
				var out = {};
				for(var ii in checks) {
					var present = $(checks[ii]).length > 0;
					out[checks[ii]] = present;
					}
				var outJson = JSON.stringify(out, null, 4);
				console.log(outJson);
			});
		} else {
Exemple #6
0
var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

if(require.main == module) {
	if (typeof String.prototype.startsWith != 'function') {
  		// see below for better implementation!
	  String.prototype.startsWith = function (str){
	 	 return this.indexOf(str) == 0;
  	  };
	}
    program
        .option('-c, --checks <check_file>', 'Path to checks.json', clone(assertFileExists), CHECKSFILE_DEFAULT)
        .option('-f, --url <url>', 'URL to the html page to be verified', clone(assertUrlExists), HTMLFILE_DEFAULT)
        .parse(process.argv);
    // use checkHtmlFile for injecting restler response handlers    
    var checkjson = rest.get(program.url.toString()).on('complete', checkHtmlFile('sample', program.checks, function(data){
		if(data == null){
			console.log("No data returned!");
		}else {
			var outJson = JSON.stringify(data, null, 4);
			console.log(outJson);
		}
	})); 
} else {
    exports.checkHtmlFile = checkHtmlFile;
}

Exemple #7
0

var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

var printJson = function(json){
  var outJson = JSON.stringify(json, null, 4);
  console.log(outJson);
};

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, --url <url>', 'Link to url')
	.parse(process.argv);

    if(program.url){
	if(program.url.indexOf('http') == 0){
	   checkUrlFile(program.url,program.checks, printJson);
	}
    }else{
	checkFile(program.file, program.checks, printJson);
    }
} else {
    exports.checkHtmlFile = checkHtmlFile;
}
Exemple #8
0
	    var outJson = JSON.stringify(checkJson, null, 4);
	    console.log(outJson);
        }
    };
    return checkUrl;
};

var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

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, --url <html_url>', 'URL for HTML to check', clone(assertUrlExists), HTMLURL_DEFAULT)
        .parse(process.argv);
    if (program.url.toString() != "") {
	var checkUrl = buildfn(program.checks);
	restler.get(program.url.toString()).on('complete', checkUrl);
    } else {
	var checkJson = checkHtmlFile(program.file, program.checks);
	var outJson = JSON.stringify(checkJson, null, 4);
	console.log(outJson);
    }
} else {
    exports.checkHtmlFile = checkHtmlFile;
}
Exemple #9
0
var assertURLExists = function(inurl){
                var url = program.url.toString();
                rest.get(url).on('complete',function(result,response){
                        console.log(result);
                });
        }
Exemple #10
0
    };
   return response2url;
 };


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,--url <url_link>', 'URL LINK')
.parse(process.argv);
    //var apiurl = program.url.toString() || URL_DEFAULT;

 if(program.url){
     var apiurl  = program.url.toString();
     var response2url = build(HTMLFILE_DEFAULT,CHECKSFILE_DEFAULT);
     rest.get(apiurl).on('complete',response2url);
     //console.log(program.file);
     //var checkJson = checkHtmlFile(program.file,program.checks);
     //var outJson = JSON.stringify(checkJson, null, 4);
     //console.log(outJson);});
 }
 else{
     var checkJson = checkHtmlFile(program.file, program.checks);
     var outJson = JSON.stringify(checkJson, null, 4);
     fs.writeFileSync('output.json',outJson);
     console.log(outJson);
 }

}
Exemple #11
0
    }
    return out;
};

var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

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, --url <html_url>', 'Url to index.html', URL_DEFAULT)
        .parse(process.argv);
    
    if(program.url!= "no" && program.url.toString().length>0){
    	// validar html asincrono
    	validarHtmlUrlAsincrono(program.url, program.checks);
    	
    } else{
    	var checkJson = checkHtmlFile(program.file, program.checks);
        var outJson = JSON.stringify(checkJson, null, 4);
        console.log(outJson);	
    }
    
    
} else {
    exports.checkHtmlFile = checkHtmlFile;
}
Exemple #12
0
var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

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, --url <check_url>', 'Url to check')
        .parse(process.argv);

    if(program.url) {
    	var instr = program.url.toString();
            rest.get(instr).on('complete', function(result){
            $ = cheerio.load(result);
             var checks = loadChecks(program.checks).sort();
            var out = {};
            for(var ii in checks) {
                var present = $(checks[ii]).length > 0;
                out[checks[ii]] = present;
            }
            var outJson = JSON.stringify(out, null, 4);
            console.log(outJson);
         });
    }else{
    	var checkJson = checkHtmlFile(program.file, program.checks);
    	var outJson2 = JSON.stringify(checkJson, null, 4);
        console.log(outJson2);
Exemple #13
0
	var checks = loadChecks(checksfile).sort();
	var out = {};
	for(var ii in checks) {
            var present = $(checks[ii]).length > 0;
            out[checks[ii]] = present;
	}
	onResult(out);
    });
};

var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

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, --url <url>', 'url', clone(assertWebFile))
        .parse(process.argv);
    var filename = program.url ? program.url.toString() : program.file;
    checkHtmlFile(filename, program.checks, function (checkJson) {
        var outJson = JSON.stringify(checkJson, null, 4);
        console.log(outJson);
    });
} else {
    exports.checkHtmlFile = checkHtmlFile;
}
Exemple #14
0
    $ = cheerioHtmlFile(htmlfile);
    for(var ii in checks) {
       var present = $(checks[ii]).length > 0;
       out[checks[ii]] = present;
    }
    var outJson = JSON.stringify(out, null, 4);
    console.log(outJson);
};

var clone = function(fn) {
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

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, --url <url>', 'URL to download')
        .parse(process.argv);
    if (program.url && (/^http/).test(program.url.toString())){
      checkUrl(program.url, program.checks);
    } else {
      checkHtmlFile(program.file, program.checks);
    }
} else {
    exports.checkHtmlFile = checkHtmlFile;
}
Exemple #15
0
    .fin(function () {
        if (commander.clientId) {
            imgur.setClientId(commander.clientId);
        }

        if (commander.show) {

            console.log(imgur.getClientId());

        } else if (commander.clear) {

            imgur.clearClientId()
                .fail(function (err) {
                    console.error('Unable to clear client id (%s)', err.message);
                });

        } else if (commander.save) {

            imgur.saveClientId(commander.save)
                .fail(function (err) {
                    console.error('Unable to save client id (%s)', err.message);
                });

        } else if (commander.credits) {

            imgur.getCredits()
                .then(function (json) {
                    console.log(json.data);
                }, function (err) {
                    console.error('Unable to get credit info (%s)', err.message);
                });

        } else {

            if (commander.file.length || commander.args.length) {
                var args = commander.file.concat(commander.args);
                var albumId = commander.albumId ? commander.albumId : null;
                if (!albumId && args.length > 1) {
                    var aId, deleteHash;
                    imgur.createAlbum()
                        .then(function (json) {
                            aId = json.data.id;
                            deleteHash = json.data.deletehash;
                            console.log('Album -> https://imgur.com/a/%s', aId);
                            args.forEach(function(file, index, array) {
                                imgur.uploadFile(file, deleteHash)
                                    .then(function (json) {
                                        var output = util.format('%s -> %s', file, json.data.link);
                                        console.log(output);
                                    }, function (err) {
                                        console.error('%s (%s)', err.message, file);
                                    });
                            });
                        }, function (err) {
                            console.error('Unable to create album (%s)', err.message);
                        });
                } else {
                    args.forEach(function(file, index, array) {
                        imgur.uploadFile(file, albumId)
                            .then(function (json) {
                                var output;
                                if (args.length > 1) {
                                    output = util.format('%s -> %s', file, json.data.link);
                                } else {
                                    output = json.data.link;
                                }
                                console.log(output);
                            }, function (err) {
                                console.error('%s (%s)', err.message, file);
                            });
                    });
                }
            }

            if (commander.info.length) {
                commander.info.forEach(function (id, index, array) {
                    imgur.getInfo(id)
                        .then(function (json) {
                            console.log(json.data);
                        }, function (err) { console.log(err.message); });
                });
            }


            if (commander.base64.length) {
                commander.base64.forEach(function(str, index, array) {
                    imgur.uploadBase64(str)
                        .then(function (json) {
                            var output;
                            if (commander.base64.length > 1) {
                                output = util.format('%s... -> %s', str.substr(0, 7), json.data.link);
                            } else {
                                output = json.data.link;
                            }
                            console.log(output);
                        }, function (err) {
                            var output = util.format('%s (%s...)', err.message, str.substr(0, 7));
                            console.error(output);
                        });
                });
            }


            if (commander.url.length) {
                commander.url.forEach(function(url, index, array) {
                    imgur.uploadUrl(url)
                        .then(function (json) {
                            var output;
                            if (commander.url.length > 1) {
                                output = util.format('%s -> %s', url, json.data.link);
                            } else {
                                output = json.data.link;
                            }
                            console.log(output);
                        }, function (err) {
                            console.error('%s (%s)', err.message, url);
                        });
                });
            }
        }
    });
Exemple #16
0
    // Workaround for commander.js issue.
    // http://stackoverflow.com/a/6772648
    return fn.bind({});
};

if(require.main == module) {
    program
        .option('-f, --file <html_file>', 'Path to index.html', clone(assertFileExists), HTMLFILE_DEFAULT)
        .option('-c, --checks <check_file>', 'Path to checks.json', clone(assertFileExists), CHECKSFILE_DEFAULT)
        .option('-u, --url <url>','url for html file',URL_DEFAULT)
        .parse(process.argv);
var output;
output="OutputFile.html";
        if (program.url != null)
         {
         rest.get(program.url.toString()).
       on('complete', function(result)
{
            if (result instanceof Error)
               { 
                  sys.puts("Error:" +  result.message);
                  this.retry(5000);
               }   
           else
             {
               fs.writeFileSync(output,result);
             }  
           });
         var checkJson = checkHtmlFile(output, program.checks);
        }
else