Skip to content

Instantly share code, notes, and snippets.

@bascht
Created July 25, 2013 16:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bascht/6081707 to your computer and use it in GitHub Desktop.
Save bascht/6081707 to your computer and use it in GitHub Desktop.
Small KVB Monitor for dashing
class Dashing.NextTrains extends Dashing.Widget
ready: ->
<div class="logo" data-view="Image" data-image="/kvb.png"></div>
<table class="list-nostyle trains">
<tr data-id="next_trains" data-foreach-item="next_trains">
<td class="line" data-bind="item.line"></td>
<td class="direction" data-bind="item.direction"></td>
<td class="time" data-bind="item.time"></td>
</tr>
</table>
# encoding: UTF-8
require 'open-uri'
require 'nokogiri'
# KVB iFrame for (e.g.) Drehbrücke
uri = 'http://www.kvb-koeln.de/generated/?aktion=show&code=46'
SCHEDULER.every '15s', :first_in => 0 do |job|
# windows encoding. Nice one, KVB!
source = open(uri, 'r:windows-1252').read()
dom = Nokogiri::HTML.parse(source)
table = dom.css('body > table:nth-child(2)')
stations = table.css('tr')
next_trains = stations.collect do |station|
{ line: station.css("td:nth-child(1)").text().strip(),
direction: station.css("td:nth-child(2)").text().strip(),
time: station.css("td:nth-child(3)").text().strip() }
end
# Only send the next 5 trains
send_event('next_trains', {next_trains: next_trains[0..7]})
end
.next_trains {
background-color: #fff;
.updated-at {
color: rgba(0, 0, 0, 0.7);
}
.logo {
background-color: transparent;
float: right;
padding-top: 0;
padding-bottom: 5px;
}
.logo img {
float: right;
}
table.trains {
background-color: #BF3030;
font-size: 20px;
border-radius: 5px;
-moz-border-radius: 5px;
}
table.trains td.line {
text-align: middle;
font-weight: bold;
background-color: #BF3030;
}
table.trains tr:nth-child(even) {
background-color:#A73939;
}
table.trains td.direction {
text-align: left;
padding-left: 1em;
}
}
@fhemberger
Copy link

New link to generator website:
https://www.kvb.koeln/fahrtinfo/widget-generator/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment