Last active
August 29, 2015 14:06
-
-
Save jquense/19c34095b1dc71101caf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you are calling
getDay
, and passing in the functiongetWeek
as the callback, sogetDay
will call thegetWeek
function after it finishes it stuff,getWeek
does the same thing forgetSchema