Montréal public transit commands for Ubiquity

stm-bus

Accepts the line number and brings up the STM schedule page for that bus route. Example:

stm-bus 211

amt-train

Looks up AMT commuter train schedule for specified parameters. Examples:

amt-train dorion-rigaud
amt-train dorion-rigaud to downtown
amt-train dorion-rigaud to suburbs on sunday

CmdUtils.CreateCommand({ name : "stm-bus", homepage : "http://www.mricon.com/ubi/", author : {name: "Konstantin Ryabitsev", email: "icon@mricon.com"}, license : "GPL", description: "Look up STM bus schedule (Montreal, Canada)", help : "Type in the bus number to go to the STM site with the timetable for that route", takes : {"route": noun_arb_text}, preview: function (pblock, route) { if (route.text) { pblock.innerHTML = "Show schedule for bus #" + route.text; } else { pblock.innerHTML = this.help; } }, execute: function (route) { if (parseInt(route.text) != route.text) { displayMessage(route.text + " is not a bus route number"); return; } var url = "http://www.stm.info/bus/geomet/geo{BUS}.htm"; url = url.replace(/{BUS}/g, route.text); Utils.openUrlInBrowser(url); }, }); // Derived from http://www.amt.qc.ca/tc/train/plans/ var amt_lines = { "deux-montagnes" : 1, "dorion-rigaud" : 2, "blainville-st-jerome": 3, "mont-st-hilaire" : 20, "delson-candiac" : 21 }; var amt_directions = { "downtown": "centre", "suburbs" : "exterieur" }; var amt_days = { "weekday" : 1, "monday" : 1, "tuesday" : 1, "wednesday": 1, "thursday" : 1, "friday" : 1, "saturday" : 2, "sunday" : 3 }; var all_amt_lines = []; var all_amt_directions = []; var all_amt_days = []; for (line in amt_lines) { all_amt_lines.push(line); } for (direction in amt_directions) { all_amt_directions.push(direction); } for (day in amt_days) { all_amt_days.push(day); } var noun_type_amt_line = new CmdUtils.NounType("line name", all_amt_lines); var noun_type_amt_direction = new CmdUtils.NounType("downtown/suburbs", all_amt_directions); var noun_type_amt_day = new CmdUtils.NounType("day of the week", all_amt_days); CmdUtils.CreateCommand({ name : "amt-train", homepage : "http://www.mricon.com/ubi/", author : {name: "Konstantin Ryabitsev", email: "icon@mricon.com"}, license : "GPL", description: "Look up AMT train schedule (Montreal, Canada)", help : "Example: amt-train <b>dorion-rigaud</b> [to <b>downtown</b>] [on <b>sunday</b>]", takes : {"line": noun_type_amt_line}, modifiers : {"to": noun_type_amt_direction, "on": noun_type_amt_day}, preview: function (pblock, line, mods) { pblock.innerHTML = this.help; }, execute: function (line, mods) { // set defaults var amt_line = "dorion-rigaud"; var amt_direction = "downtown"; var amt_day = "weekday"; // see if today is Sunday or Saturday var currentTime = new Date(); var dow = currentTime.getDay(); if (dow == 0) { amt_day = "sunday"; } else if (dow == 6) { amt_day = "saturday"; } // look at what we were given if (line.text) { var amt_line = line.text.toLowerCase(); if (jQuery.inArray(amt_line, all_amt_lines) == -1) { displayMessage("Invalid train line name"); return; } } if (mods["to"].text) { amt_direction = mods["to"].text.toLowerCase(); if (jQuery.inArray(amt_direction, all_amt_directions) == -1) { displayMessage("Direction must be either 'downtown' or 'outside'."); return; } } if (mods["on"].text) { amt_day = mods["on"].text.toLowerCase(); if (jQuery.inArray(amt_day, all_amt_days) == -1) { displayMessage("Invalid day of the week."); return; } } var url = "http://www.amt.qc.ca/tc/train/horaires/horaires_fs.asp?" + "direction={AMT_DIRECTION}&codejour={AMT_DAY}&ligne={AMT_LINE}"; url = url.replace(/{AMT_DIRECTION}/g, amt_directions[amt_direction]); url = url.replace(/{AMT_DAY}/g, amt_days[amt_day]); url = url.replace(/{AMT_LINE}/g, amt_lines[amt_line]); Utils.openUrlInBrowser(url); }, });