File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ var url = require ( 'url' )
2+ , exec = require ( 'child_process' ) . exec
3+ , fs = require ( 'fs' )
4+ , csv = require ( 'csv' ) ;
5+
6+ exports . downloadGTFS = function ( req , res ) {
7+ var DOWNLOAD_DIR = './downloads/' + req . params . agency + '/' ;
8+ var base_url = 'http://www.gtfs-data-exchange.com/agency/' ;
9+ var file_url = base_url + req . params . agency + '/latest.zip' ;
10+
11+ // extract the file name
12+ var file_name = url . parse ( file_url ) . pathname . split ( '/' ) . pop ( ) ;
13+
14+ // excute wget using child_process' exec function
15+ var wget = 'wget -N -O ' + DOWNLOAD_DIR + 'latest.zip ' + file_url ;
16+ var child = exec ( wget , function ( err , stdout , stderr ) {
17+ if ( ! err ) {
18+ //unzip file
19+ var unzip = 'unzip ' + DOWNLOAD_DIR + 'latest.zip -d ' + DOWNLOAD_DIR ;
20+ var child = exec ( unzip , function ( err , stdout , stderr ) {
21+ if ( ! err ) {
22+ res . contentType ( 'application/json' ) ;
23+ res . send ( {
24+ success : true
25+ } ) ;
26+ console . log ( file_name + ' downloaded to ' + DOWNLOAD_DIR ) ;
27+
28+ }
29+ } ) ;
30+
31+ } else {
32+ //something didn't work
33+ res . contentType ( 'application/json' ) ;
34+ res . send ( {
35+ success : false
36+ } ) ;
37+ }
38+ } ) ;
39+ }
40+
41+ exports . parseGTFS = function ( req , res ) {
42+
43+ }
Original file line number Diff line number Diff line change 77 , "mongoose" : " >= 1.1.0"
88 , "redis" : " >= 0.6.7"
99 , "jade" : " >= 0.19.0"
10+ , "csv" : " >= 0.0.10"
1011 }
1112}
Original file line number Diff line number Diff line change 1- var errors = require ( './lib/util/errors' ) ;
1+ var errors = require ( './lib/util/errors' )
2+ , api = require ( './lib/util/api' ) ;
23
34module . exports = function routes ( app ) {
45
5- app . get ( '/api' , function ( req , res ) {
6+ //Routelist
7+ app . get ( '/api/routes/:agency' , function ( req , res ) {
68
79 //Spit back variables from URL
810 for ( i in req . query ) { console . log ( i + ": " + req . query [ i ] ) ; }
911
1012 res . contentType ( 'application/json' ) ;
11-
1213 res . send ( {
13- error : 'none'
14+ agency : req . params . agency
15+ , routes : [
16+ {
17+ shortName : '35' ,
18+ routeName : '35-Eureka' ,
19+ predictionType : 'schedule'
20+ }
21+ ]
1422 } ) ;
1523
1624 } ) ;
17-
18- app . all ( '*' , function notFound ( req , res , next ) {
19- next ( new errors . NotFound ) ;
25+
26+
27+ app . get ( '/api/routes/download/:agency' , api . downloadGTFS ) ;
28+
29+ //Nothing specified
30+ app . all ( '*' , function notFound ( req , res ) {
31+
32+ res . contentType ( 'application/json' ) ;
33+ res . send ( {
34+ error : 'No API call specified'
35+ } ) ;
2036 } ) ;
2137
2238}
You can’t perform that action at this time.
0 commit comments