Created
July 17, 2012 23:21
-
-
Save tjlytle/3132821 to your computer and use it in GitHub Desktop.
on{X} script to check traffic
This file contains hidden or 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
//check route to work and alret for problems | |
var checkRoute = function(showSummery){ | |
//TODO: get device location | |
var wps = []; | |
// get the traffic on 78 | |
wps[0] = '40.55697, -75.99809'; | |
wps[1] = '40.56785, -75.51876'; | |
// get the traffic feed | |
console.info('about to call traffic feeds'); | |
feeds.traffic.get( | |
{wps: wps, unittype: 'm'}, | |
function(traffic, textStatus, response) { | |
for (var i = 0; i < traffic.warnings.length; i++){ | |
var notification = device.notifications.createNotification('Traffic Warning'); | |
notification.content = traffic.warnings[i].severity + ' ' + traffic.warnings[i].text; | |
notification.show(); | |
} | |
if(!notification && showSummery){ | |
var duration = traffic.totalTravelDuration/60; | |
var notification = device.notifications.createNotification('Traffic info'); | |
notification.content = 'Time to work: ' + duration + ' minutes'; | |
notification.show(); | |
} | |
}, | |
function(response, textStatus) { | |
console.info('got error : ' + textStatus); | |
} | |
); | |
}; | |
//setup schedule | |
var setupTimer = function(){ | |
var now = new Date(); | |
//check at 4pm | |
var timerStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16, 0, 0, 0); | |
console.info('offest: ' + timerStart.getTimezoneOffset()); | |
console.info('timestamp: ' + timerStart.getTime()); | |
// subscribe the scheduled task to a daily timer | |
device.scheduler.setTimer({ | |
name: 'workTraffic', | |
time: timerStart.getTime(), | |
interval: 'day', | |
repeat: true, | |
exact: false | |
}, | |
monitorRoute); | |
console.info('setup timer'); | |
} | |
//monitor the traffic | |
var monitorRoute = function() { | |
console.info('looks like it time to work'); | |
//if it's not firday or saturday - who cares? | |
var now = new Date(); | |
if(now.getDay() != 5 && now.getDay() != 6){ | |
console.info('not a valid day'); | |
return; | |
} | |
//check the route | |
checkRoute(true); | |
//TODO: check every few minutes until 7:00 | |
}; | |
//kick it off | |
setupTimer(); |
This file contains hidden or 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
//check route to work and alret for problems | |
var checkRoute = function(showSummery){ | |
//TODO: get device location | |
var wps = []; | |
// get the traffic on 78 | |
wps[0] = '40.55697, -75.99809'; | |
wps[1] = '40.56785, -75.51876'; | |
// get the traffic feed | |
console.info('about to call traffic feeds'); | |
feeds.traffic.get( | |
{wps: wps, unittype: 'm'}, | |
function(traffic, textStatus, response) { | |
for (var i = 0; i < traffic.warnings.length; i++){ | |
var notification = device.notifications.createNotification('Traffic Warning'); | |
notification.content = traffic.warnings[i].severity + ' ' + traffic.warnings[i].text; | |
notification.show(); | |
} | |
if(!notification && showSummery){ | |
var duration = traffic.totalTravelDuration/60; | |
var notification = device.notifications.createNotification('Traffic info'); | |
notification.content = 'Time to work: ' + duration + ' minutes'; | |
notification.show(); | |
} | |
}, | |
function(response, textStatus) { | |
console.info('got error : ' + textStatus); | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment