-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work on downloading and reading GTFS
- Loading branch information
1 parent
03ce7a6
commit 90b1d3a
Showing
3 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var url = require('url') | ||
, exec = require('child_process').exec | ||
, fs = require('fs') | ||
, csv = require('csv'); | ||
|
||
exports.downloadGTFS = function(req, res){ | ||
var DOWNLOAD_DIR = './downloads/' + req.params.agency + '/'; | ||
var base_url = 'http://www.gtfs-data-exchange.com/agency/'; | ||
var file_url = base_url + req.params.agency + '/latest.zip'; | ||
|
||
// extract the file name | ||
var file_name = url.parse(file_url).pathname.split('/').pop(); | ||
|
||
// excute wget using child_process' exec function | ||
var wget = 'wget -N -O ' + DOWNLOAD_DIR + 'latest.zip ' + file_url; | ||
var child = exec(wget, function(err, stdout, stderr) { | ||
if (!err){ | ||
//unzip file | ||
var unzip = 'unzip ' + DOWNLOAD_DIR + 'latest.zip -d ' + DOWNLOAD_DIR; | ||
var child = exec(unzip, function(err, stdout, stderr) { | ||
if(!err){ | ||
res.contentType('application/json'); | ||
res.send({ | ||
success: true | ||
}); | ||
console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR); | ||
|
||
} | ||
}); | ||
|
||
} else { | ||
//something didn't work | ||
res.contentType('application/json'); | ||
res.send({ | ||
success: false | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
exports.parseGTFS = function(req, res){ | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
, "mongoose": ">= 1.1.0" | ||
, "redis": ">= 0.6.7" | ||
, "jade": ">= 0.19.0" | ||
, "csv": ">= 0.0.10" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
var errors = require('./lib/util/errors'); | ||
var errors = require('./lib/util/errors') | ||
, api = require('./lib/util/api'); | ||
|
||
module.exports = function routes(app){ | ||
|
||
app.get('/api', function(req, res){ | ||
//Routelist | ||
app.get('/api/routes/:agency', function(req, res){ | ||
|
||
//Spit back variables from URL | ||
for(i in req.query){ console.log(i+": "+req.query[i]); } | ||
|
||
res.contentType('application/json'); | ||
|
||
res.send({ | ||
error: 'none' | ||
agency: req.params.agency | ||
, routes: [ | ||
{ | ||
shortName: '35', | ||
routeName: '35-Eureka', | ||
predictionType: 'schedule' | ||
} | ||
] | ||
}); | ||
|
||
}); | ||
|
||
app.all('*', function notFound(req, res, next) { | ||
next(new errors.NotFound); | ||
|
||
|
||
app.get('/api/routes/download/:agency', api.downloadGTFS); | ||
|
||
//Nothing specified | ||
app.all('*', function notFound(req, res) { | ||
|
||
res.contentType('application/json'); | ||
res.send({ | ||
error: 'No API call specified' | ||
}); | ||
}); | ||
|
||
} |