-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.coffee
37 lines (28 loc) · 1.14 KB
/
index.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fs = require 'fs'
path = require 'path'
_ = require 'underscore'
glob = require 'glob'
async = require 'async'
timetable = require './lib/timetable'
stops = require './lib/stops'
routes = require './lib/routes'
glob 'schedules/**.csv', (err, files) ->
(_ files).each (file) ->
stream = fs.createReadStream file
timetable stream, (err, data) ->
fs.writeFileSync "timetables/#{path.basename file, '.csv'}.json", JSON.stringify data
stops.importDefault (err, stops) ->
data = JSON.stringify stops
fs.writeFileSync 'stops/allStops.json', data
routes.importDefault (err, routes) ->
readStops = (file, callback) ->
stream = fs.createReadStream file
stops.importCsvStream stream, (err, data) ->
callback undefined, (_ data).map (s) -> Number s.stopId
addStops = (route, callback) ->
glob "stops/#{route.route}-*.csv", (err, files) ->
async.map files, readStops, (err, stops) ->
route.stops = stops
callback undefined, route
async.map routes, addStops, (err, routes) ->
fs.writeFileSync 'routes/routes.json', JSON.stringify routes