UNPKG

timetable

Version:

Using GTFS and other sources to produce beautiful and usable timetables for public transport.

102 lines (79 loc) 2.45 kB
// Generated by CoffeeScript 1.7.1 (function() { var ASYNC, GTFS_READER, READER, REGISTRY, TRM, alert, badge, debug, echo, help, info, log, options, rainbow, rpr, urge, warn, whisper; TRM = require('coffeenode-trm'); rpr = TRM.rpr.bind(TRM); badge = 'TIMETABLE/main'; log = TRM.get_logger('plain', badge); info = TRM.get_logger('info', badge); whisper = TRM.get_logger('whisper', badge); alert = TRM.get_logger('alert', badge); debug = TRM.get_logger('debug', badge); warn = TRM.get_logger('warn', badge); help = TRM.get_logger('help', badge); urge = TRM.get_logger('urge', badge); echo = TRM.echo.bind(TRM); rainbow = TRM.rainbow.bind(TRM); ASYNC = require('async'); GTFS_READER = require('./GTFS-READER'); READER = require('./READER'); REGISTRY = require('./REGISTRY'); options = require('../options'); this.show_db = function(db, handler) { var $, P, count, input, query; P = require('pipedreams'); $ = P.$.bind(P); query = { gte: 'gtfs/stops/', lte: 'gtfs/stops/\xff' }; help('show registry'); count = 0; return input = (db.createReadStream(query)).pipe($(function(record, handler) { count += 1; return handler(null, record); })).pipe(P.$on_end(function() { help(query); help(count, "records in DB"); return handler(null, db); })); }; this.main = function(handler) { var folder_exists, registry, tasks, _ref; tasks = []; _ref = REGISTRY._new_registry(), folder_exists = _ref[0], registry = _ref[1]; if (folder_exists) { help("DB already exists"); help("skipping GTFS_READER.main()"); } else { tasks.push(function(async_handler) { return GTFS_READER.main(registry, async_handler); }); } tasks.push(function(async_handler) { return REGISTRY.flush(registry, async_handler); }); ASYNC.series(tasks, function(error) { if (error != null) { return handler(error); } return handler(null, registry); }); return null; }; if (module.parent == null) { this.main((function(_this) { return function(error, registry) { if (error != null) { throw error; } return _this.show_db(registry, function(error) { if (error != null) { throw error; } return help('ok'); }); }; })(this)); } }).call(this);