Skip to content

Instantly share code, notes, and snippets.

@stefan-walluhn
Last active August 12, 2016 07:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefan-walluhn/8c617513b6188547a864 to your computer and use it in GitHub Desktop.
Save stefan-walluhn/8c617513b6188547a864 to your computer and use it in GitHub Desktop.
Havag Info

Havag Info

Preview

Screenshot: http://download.terminal21.de/projects/havag.png

Description

Havag Info is a Dashing widget which displays information on trams and buses in Halle (Saale) / Germany operated by Havag.

Dependencies

Add the following gem to the Gemfile:

gem 'httpclient'

and run bundle install.

Havag ruby library

ruby_on_havag

Clone repo (or download RAW from project page):

git clone https://github.com/Terminal21/ruby_on_havag.git

Copy to lib directory

cp ruby_on_havag/havag.rb PATH_TO_DASHBOARD/lib

Be careful, lib/havag.rb and job/havag.rb (see below) are different files! Do not mix them!

Usage

Copy havag.rb to the '/jobs' directory. Create a folder called havag under /widgets. Copy havag.coffee, havag.html and havag.scss into /widgets/havag. Copy havag.png into /assets/images/.

Add the following code snippet to your dashboard .erb file:

<li data-row="1" data-col="1" data-sizex="2" data-sizey="2">
   <div data-id="havag" data-view="Havag" data-title="Havag" style="background-color:#12B0C5;"> ></div>
</li>

Settings

Specify the tram station you want to display in the widget by setting the 'station' variable in job/havag.rb

You can figure out what stations are available by executing the library as a ruby program ruby lib/havag.rb

class Dashing.Havag extends Dashing.Widget
ready: ->
<h1 class="train title" data-bind="station"></h1>
<table class="trains">
<tr>
<th>Line</th>
<th>Destination</th>
<th>Departure</th>
<th>Delay</th>
</tr>
<tr data-id="next_trains" data-foreach-item="next_trains" class="next_trains">
<td class="line" data-bind="item.line"></td>
<td class="destination" data-bind="item.destination"></td>
<td class="departure_scheduled" data-bind="item.departure_scheduled"></td>
<td class="delay" data-bind="item.delay"></td>
</tr>
</table>
# encoding: utf-8
station = "Talstraße"
havag = Havag.new
SCHEDULER.every '20s', :first_in => 0 do |job|
next_trains = havag.getNextTrains(station)
next_trains.each do |train|
delay = (train[:departure_real].to_time - train[:departure_scheduled].to_time).to_i
train[:delay] = Time.at(delay).strftime("%M:%S")
train[:departure_scheduled] = train[:departure_scheduled].strftime("%H:%M")
end
send_event('havag', {station: station, next_trains: next_trains[0..9]})
end
h1.train {
background: url("/assets/havag.png") left center no-repeat;
background-size: auto 100%;
margin-left: 10px;
}
.trains td, .trains th {
padding: 10px;
}
.next_trains {
border-top: 1px solid #fff;
}
@levinceeent
Copy link

Hello!
Is it possible to adapt this for the VBN (Verkehrsverbund Bremen/Niedersachsen)? If yes, how ?
Thanks 👍

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