Skip to content

Instantly share code, notes, and snippets.

@deversmann
Last active April 26, 2022 18:32
Show Gist options
  • Save deversmann/e0ffa81df3e25171f993b1bc40c91b18 to your computer and use it in GitHub Desktop.
Save deversmann/e0ffa81df3e25171f993b1bc40c91b18 to your computer and use it in GitHub Desktop.
cta_bus_widget

cta_bus_widget: Smashing Widget for CTA Bus Routes

Description

A widget for the Smashing Dashboard system to display bus arrival times at one or more stops along Chicago's CTA bus routes.

Screenshot

cta_bus_widget screenshot

Installation

smashing install e0ffa81df3e25171f993b1bc40c91b18

or

  • Copy cta_bus_widget.coffee, cta_bus_widget.html, cta_bus_widget.scss into widgets/cta_bus_widget/
  • Copy cta_bus_widget.rb int jobs/

Usage

In cta_bus_widget.rb replace the following:

Add the widget to your dashboard layout like this:

<li data-row="1" data-col="1" data-sizex="3" data-sizey="1">
    <div data-id="cta_bus_widget" data-view="CTABusWidget"></div>
</li>

A width of either 2 or 3 usually looks good. If a height of 2 or more is used, the max variable in cta_bus_widget.rb can be changed to increase the number of results to fill the space.


Contents of this gist licensed as follows:

MIT License

Copyright (c) 2021 Damien Eversmann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class Dashing.CTABusWidget extends Dashing.Widget
ready: ->
onData: (data) ->
<h3 class="title">CTA Bus Times</h3>
<table class="list-nostyle busses">
<tr><th style="width:30%">Rte #/Dest</th><th style="width:60%">Stop</th><th style="width:10%">Arrival</th></tr>
<tr data-id="prd" data-foreach-item="prd">
<td class="rt">
<p class="rt" data-bind="item.rt"></p>
<p class="des" data-bind="item.des"></p>
</td>
<td class="stp">
<p class="stpnm" data-bind="item.stpnm"></p>
<p class="rtdir" data-bind="item.rtdir"></p>
</td>
<td class="prdctdn" data-bind="item.prdctdn"></td>
</tr>
</table>
<span class="updated-at" data-bind="updatedAtMessage"></span>
<i class="fa fa-bus icon-background" style="margin-top: 50px;"></i>
# encoding: UTF-8
require 'net/http'
require 'uri'
require 'json'
cta_api_key = ENV["CTA_BUS_API_KEY"] # https://www.transitchicago.com/developers/bustracker/
bus_stop_list = ENV["CTA_BUS_STOPS"] # comma separated list
max = 6
SCHEDULER.every '15s', :first_in => 0 do |job|
http = Net::HTTP.new("www.ctabustracker.com", 80)
response = http.request(Net::HTTP::Get.new("/bustime/api/v2/getpredictions?key=#{cta_api_key}&stpid=#{bus_stop_list}&top=#{max}&format=json"))
json = JSON.parse(response.body)
prds = json["bustime-response"]["prd"]
send_event('cta_bus_widget', prd: prds)
end
$background-color: #2166b1;
/* using css specificity to override the .widget class which sets to middle */
div.cta_bus_widget {
vertical-align: top;
}
.cta_bus_widget {
background-color: $background-color;
padding-left: 10px;
padding-right: 10px;
.updated-at {
top: 0px;
right: 2px;
left: unset;
color: rgba(255,255,255,0.5);
}
table.busses {
line-height: 22px;
}
table.busses tr:nth-child(even) {
background-color: rgba(0,0,0,0.3);
}
table.busses td {
border-top: white solid 2px;
}
table.busses td.rt {
text-align: middle;
}
table.busses td p.rt {
text-align: middle;
font-weight: bold;
font-size: 24px;
}
table.busses td p.des {
text-align: middle;
font-size: 16px;
white-space: nowrap;
}
table.busses td p.rtdir {
font-size: 15px;
}
table.busses td p.stpnm {
font-size: 22px;
}
table.busses td p.rtdir {
font-size: 15px;
}
table.busses td.prdctdn {
font-size: 30px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment