Skip to content
Browse files

Added partial nextbus and kittenwar support

Kittenwar support using YQL and ajax, will not support voting.
Nextbus requires proper theming, looks ugly.
  • Loading branch information...
1 parent 5391b37 commit 39d967f15c6ea76ced10b205b59a29d73d7cab91 Ahron Train committed Jun 2, 2012
Showing with 154 additions and 13 deletions.
  1. +0 −1 app/css/app.sass
  2. +10 −1 app/css/cats.sass
  3. +41 −0 app/js/app.js.coffee
  4. +17 −8 app/views/cats.haml
  5. +2 −2 app/views/home.haml
  6. +1 −1 app/views/street_cars.haml
  7. +46 −0 lib/js/kittenwar.js
  8. +37 −0 lib/js/nextbus.js
View
1 app/css/app.sass
@@ -116,4 +116,3 @@ div.row.music-player
display: inline
color: #444
-
View
11 app/css/cats.sass
@@ -8,6 +8,15 @@ h3.sub-header
font-size: 200%
margin-top: 30px
font-weight: bold
+ text-align: center
+
+
+.kitten-names
+ color: #666
+ font-size: 200%
+ margin-bottom: 30px
+ font-weight: bold
+ text-align: center
.kitten-images-background
background: #F9F9F9
@@ -44,4 +53,4 @@ h3.sub-header
margin-bottom: 20px
.label
- font-size: 70%
+ font-size: 70%
View
41 app/js/app.js.coffee
@@ -14,6 +14,47 @@ $ ->
$clock.html(Date.create().format '{Weekday} {Month} {d}, {12hr}:{mm}{tt}')
window.setInterval clock_tick, 1000
+# StreetCar
+$ ->
+
+ routes =
+ spadinanorth:
+ route: 510
+ stopid: 6577
+ spadinasouth:
+ route: 510
+ stopid: 3159
+ collegeeast:
+ route: 506
+ stopid: 1010
+ collegewest:
+ route: 506
+ stopid: 9193
+ dundaseast:
+ route: 505
+ stopid: 6046
+ dundaswest:
+ route: 505
+ stopid: 1212
+
+
+ update = ->
+ updatePrediction(510,3159,"times") #For front page
+ updatePrediction(510,6577,"timen")
+
+ predicts = for element,param of routes
+ updatePrediction(param.route, param.stopid, element)
+
+ window.setInterval update, 60000
+
+ update()
+
+
+#Cats
+$ ->
+ getKitten()
+ $(".draw-btn").click -> getKitten()
+
# Volume Control
$ ->
View
25 app/views/cats.haml
@@ -12,15 +12,24 @@
.row.kitten-images
.span6
- .image{style: "background-image: url('http://kittenwar.com/c_images/2010/09/23/194291.1.jpg')"}
+ %a{id:"kitten0vote", href: "javascript: getKitten()"}
+ .image{id: "kitten0", style: "background-image: url('http://kittenwar.com/c_images/2010/09/23/194291.1.jpg')"}
.span6
- .image{style: "background-image: url('http://kittenwar.com/c_images/2010/09/23/194291.1.jpg')"}
+ %a{id:"kitten1vote", href: "javascript: getKitten()"}
+ .image{id: "kitten1", style: "background-image: url('http://kittenwar.com/c_images/2010/09/23/194291.1.jpg')"}
.kitten-images-background
-
+.row.kitten-names
+ .span6
+ .kitten-name{:id=>"kitten0name"} Bob
+ .span6
+ .kitten-name{:id=>"kitten1name"} Joe
.row.kitten-results
.span12
- %span.results-0 42%
- of the other scientists think your
- %span.label.label-important wrong
- (oh no!). Perhaps you should try adding more science?
-
+ %span.results-0
+ Unfortunately voting is currently
+ %span.label.label-important BROKEN
+ Perhaps you should fix it with science?
+.row
+ .span12
+ .btn.btn-primary.btn-large.pull-left.draw-btn Draw
+
View
4 app/views/home.haml
@@ -52,8 +52,8 @@
.streetcar.north
.icon-arrow-up
Next North Bound Streetcar:
- .time 2:26 pm
+ .time{:id => "timen"}= #JS set
.streetcar.south
.icon-arrow-down
Next South Bound Streetcar:
- .time 1:45 pm
+ .time{:id => "times"}= #JS set
View
2 app/views/street_cars.haml
@@ -8,4 +8,4 @@
%div{:class => "#{street}-#{d}".downcase}
= # %i{:class => "icon-arrow-#{direction_map[d]}"}
= "#{street} #{d}bound".titleize
- %span.time 2:00pm
+ %span.time{:id => "#{street}#{d}"} Undefined
View
46 lib/js/kittenwar.js
@@ -0,0 +1,46 @@
+
+// Accepts a url and a callback function to run.
+function getKitten() {
+
+var site="http://kittenwar.com"
+
+ // Take the provided url, and add it to a YQL query. Make sure you encode it!
+ var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + site + '"') + '&format=xml';
+
+ // Request that YSQL string, and run a callback function.
+$.ajax({
+ type: "GET",
+ url: yql,
+ dataType: "xml",
+ success: function(xml) {
+
+ var kitten0="http://kittenwar.com";
+ var kitten1="http://kittenwar.com";
+ var kitten0name;
+ var kitten1name;
+
+ $(xml).find("a").each(function(){
+ if($(this).attr('href')=="JavaScript\:%20kitten\(\'0\'\)\;") {
+ $(this).find('img').each(function(){
+ kitten0+=$(this).attr('src');
+ kitten0name=$(this).attr('title');
+ });
+ }
+ if($(this).attr('href')=="JavaScript\:%20kitten\(\'1\'\)\;") {
+ $(this).find('img').each(function(){
+ kitten1+=$(this).attr('src');
+ kitten1name=$(this).attr('title');
+ });
+ }
+ });
+ kitten0="url\(\'" + kitten0 + "\'\)";
+ kitten1="url\(\'" + kitten1 + "\'\)";
+
+ document.getElementById("kitten0").style.backgroundImage=kitten0;
+ document.getElementById("kitten1").style.backgroundImage=kitten1;
+ document.getElementById("kitten0name").innerHTML=kitten0name;
+ document.getElementById("kitten1name").innerHTML=kitten1name;
+ }
+ });
+ }
+
View
37 lib/js/nextbus.js
@@ -0,0 +1,37 @@
+function updatePrediction(route,stop,element) {
+var times= new Array();
+var output="<table><tbody>";
+var numroutes = 0;
+$.ajax({
+ type: "GET",
+ url: "http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=ttc&r="+route+"&s="+stop,
+ dataType: "xml",
+ success: function(xml) {
+ $(xml).find('direction').each(function(){
+ times=new Array();
+ console.log($(this).attr("title"));
+ $(this).find('prediction').each(function(){
+ var id = $(this).attr('minutes');
+ if (id > 1)
+ times.push(id);
+ });
+ times=times.slice(0,3);
+ console.log(times.toString());
+ if (times.length > 0){
+ numroutes++;
+ output+="<tr><td>"+$(this).attr("title").split("towards")[1].split("via")[0]+":</td>";
+ output+="<td>"+times.toString()+"</td>";
+ output+="</tr>";
+ }
+ });
+ output += "</tbody></table>";
+ if (numroutes == 1) // Skip table crap for single destination routes
+ document.getElementById(element).innerHTML=times.slice(0,3).toString();
+ else if (output != "<table><tbody></tbody></table>")
+ document.getElementById(element).innerHTML=output;
+ else
+ document.getElementById(element).innerHTML="No Predictions";
+ }
+ });
+}
+

0 comments on commit 39d967f

Please sign in to comment.
Something went wrong with that request. Please try again.