Skip to content

Instantly share code, notes, and snippets.

@jquense
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquense/19c34095b1dc71101caf to your computer and use it in GitHub Desktop.
Save jquense/19c34095b1dc71101caf to your computer and use it in GitHub Desktop.
function getDay(callback) {
request('http://www.timeanddate.com/', function date(error, response, html){
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
$('span#ij1').each(function(i, element){
var dag = $(this).text();
console.log(dag);
//call the passed in function with dag as the first argument, getSChema is the callback
callback(dag, getSchema);
});
};
});
};
function getWeek(dag, getSchemaCallback) {
request('http://ugenr.com/', function(error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
$('span#ugenr').each(function(i, element){
ugeNr = parseInt($(this).text().split(" ")[1]);
});
if (dag == "Saturday" || dag == "Sunday"{ //Depends on language of site
var ugeNr = +1;
};
};
getSchemaCallback(ugeNr);
});
};
function getSchema(ugeNr) {
request('http://domain/services/name.ashx?idx=randnum&week='+ugeNr, function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
$('div#uge'+ugeNr).each(function(i, element){
elevNavn = $(this).children('.titledata').text();
console.log(ugeNr);
console.log(elevNavn);
})
};
});
};
getDay(getWeek);
@jquense
Copy link
Author

jquense commented Sep 9, 2014

you are calling getDay, and passing in the function getWeek as the callback, so getDay will call the getWeek function after it finishes it stuff, getWeek does the same thing for getSchema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment