Skip to content

Instantly share code, notes, and snippets.

@maclover7
Created March 29, 2014 01:39
Show Gist options
  • Save maclover7/9846790 to your computer and use it in GitHub Desktop.
Save maclover7/9846790 to your computer and use it in GitHub Desktop.
MTA NYC Subway Widget for Dashing

You know what to do.

class Dashing.Mta extends Dashing.Widget
<h1 class="title">New York Subway Status</h1>
<ol>
<li data-foreach-item="items" data-bind-class="item.name | prepend 'line-' | append ' ' | append item.status">
<span data-bind="item.name"></span>
</li>
</ol>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'nokogiri'
require 'httparty'
MTA_URL = 'http://www.mta.info/status/serviceStatus.txt'
LINES = %W[123 456 7 ACE L S BDFM NQR JZ G]
def status_as_class description
case description.downcase
when 'good service' then 'online'
when 'service change' then 'delays'
else 'offline'
end
end
def line_status line, in_lines, feed
line_status = feed
.css("line:contains(#{in_lines})")
.find {|line| line.css('name').text.chomp == in_lines}
status = line_status.css('status').text.chomp
{name: line, status: status_as_class(status)}
end
SCHEDULER.every '5m', first_in: 0 do
feed = Nokogiri::XML.parse HTTParty.get(MTA_URL)
line_statuses = LINES.collect do |lines|
lines.split(//).map do |line|
line_status(line, lines, feed)
end
end.flatten
send_event('mta', {items: line_statuses})
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #3b5cac
// ----------------------------------------------------------------------------
// Widget-comment styles
// ----------------------------------------------------------------------------
.widget-mta
background-color: $background-color
.line-1, .line-2, .line-3
background-color: rgb(239, 106, 76)
.line-4, .line-5, .line-6
background-color: rgb(82, 175, 90)
.line-7
background-color: rgb(183, 130, 211)
.line-A, .line-C, .line-E
background-color: rgb(61, 155, 227)
.line-L
background-color: rgb(153, 153, 153)
.line-S
background-color: rgb(119, 119, 119)
.line-B, .line-D, .line-F, .line-M
background-color: rgb(245, 164, 59)
.line-N, .line-Q, .line-R
background-color: rgb(251, 207, 51)
color: black
.line-J, .line-Z
background-color: rgb(172, 123, 43)
.line-G
background-color: rgb(198, 212, 38)
li
margin: 0 12px 12px 0
list-style: none
background-color: white
border-radius: 20px
padding: 4px
font-size: 110%
width: 32px
height: 32px
display: inline-block
font-weight: bold
&.delays
animation: delays 5s infinite
&.offline
opacity: 0.2
@keyframes delays
25%
opacity: 0.2
transition: opacity ease-in
50%
opacity: 1
transition: opacity ease-in
75%
opacity: 0.2
transition: opacity ease-in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment