jeudi 24 septembre 2015

http request not running on AWS Lambda

First off, I admittedly don't know much about code in general, and JavaScript in particular. I'm guessing that there's probably something trivial wrong here, but I'm truly stumped.

I basically want this: http://ift.tt/1E0FwP2

However, unlike the New York City MTA, my local bus system does not publish a JSON feed. They do have a web site, however, that provides real-time arrival data. I heavily modified the example, but it still basically does the same thing: generate a URL based on the route, direction, and stop ID given to Alexa by the user, and returns the time of the next bus. Everything is working except the function that goes out and fetches the time from the web site.

snip

var url = 'http://ift.tt/1VdHq11' + route + '&d=' + whichWay() + '&s=' + whichStop();
console.log(url);
//Get the time for the next bus
//Scrape RTA web site for our data
request(url, function (error, response, body) {
    console.log(response.statusCode);
    if (!error && response.statusCode == 200) {
        console.log(body); // Show the HTML for the Google homepage.
    }
})
//var $ = cheerio.load(body);
//nextBusTime = $('.ada;nth-child(1)').text();
//console.log(nextBusTime);

snip

The code currently runs with no errors. However, while I see the URL being generated on the console, I do NOT see either of the console.log directives in the request block at all. Further, the function won't seem to write out to global variables, and if I uncomment the var $ line, it errors out with "body not defined."

I'm sure I'm missing something trivial here, but I am stuck. Help?




Aucun commentaire:

Enregistrer un commentaire