Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added direction list and code cleanup

  • Loading branch information...
commit d151eda5dcdaa77dff2c215a1f90d4a9cca38b9a 1 parent 9037b1a
@robrighter authored
Showing with 61 additions and 10 deletions.
  1. +49 −9 lib/marta.js
  2. +12 −1 server.js
View
58 lib/marta.js
@@ -1,21 +1,50 @@
var scraper = require('scraper');
+var request = require('request');
+
+var urls = {
+ departures: 'http://webwatch.itsmarta.com/prediction.aspx?mode=d',
+ arrivals: 'http://webwatch.itsmarta.com/prediction.aspx?mode=a'
+}
function getRouteList(callback){
+ scrapeForSelectBox(callback, urls.departures, "#ddlRoutes");
+}
+
+function getDirectionList(route, callback){
+ scrapeForSelectBox(callback, urls.departures, "#ddlDirections", route);
+}
+
+function getStopList(route, direction, callback){
+
+}
+
+function scrapeForSelectBox(callback, url, slectboxid, route){
scraper({
- 'uri': 'http://webwatch.itsmarta.com/prediction.aspx?mode=d',
- 'headers': {'User-Agent': 'Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11'}
+ jar: getRouteCookieJar(route),
+ uri: url, //,
+ followRedirect: false,
+ headers: {'User-Agent': 'Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11'}
}, function(err, jQuery) {
- if (err){
- callback(err, null);
- }
- else{
- callback(null,parseSelectBySelector(jQuery, "#ddlRoutes"));
+ if (err){
+ callback(err, null);
+ }
+ else{
+ callback(null,parseSelectBySelector(jQuery, slectboxid));//"#ddlDirections"
+ }
+ });
+}
+
+function getRouteCookieJar(route){
+ var j = request.jar();
+ if(route){
+ var cookie = request.cookie('Route='+route);
+ j.add(cookie);
}
-
- });
+ return j;
}
+
function parseSelectBySelector(jQuery, selector){
var ret = {};
var i = 0;
@@ -31,7 +60,18 @@ function parseSelectBySelector(jQuery, selector){
//test
+// ROUTE LIST
getRouteList( function(err, result){
+ console.log('///////////////// ROUTE LIST ///////////////////');
+ if(err){
+ throw err;
+ }
+ console.log(result);
+});
+
+//DIRECTION LIST
+getDirectionList(148, function(err, result){
+ console.log('///////////// DIRECTION LIST /////////////////');
if(err){
throw err;
}
View
13 server.js
@@ -69,7 +69,18 @@ server.get('/', function(req,res){
}
});
});
-
+
+server.get('/cookie-test', function(req,res){
+ console.log(req);
+ res.render('index.jade', {
+ locals : {
+ title : 'Your Page Title'
+ ,description: 'Your Page Description'
+ ,author: 'Your Name'
+ ,analyticssiteid: 'XXXXXXX'
+ ,thetext: "DASHBOARD"
+ }
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.