Skip to content

Instantly share code, notes, and snippets.

@kernelsmith
Forked from farrelley/README.md
Last active December 8, 2025 17:24
Show Gist options
  • Select an option

  • Save kernelsmith/4abfb7d7525e7e42a4ce to your computer and use it in GitHub Desktop.

Select an option

Save kernelsmith/4abfb7d7525e7e42a4ce to your computer and use it in GitHub Desktop.
class Dashing.Waittime extends Dashing.Widget
onData: (data) ->
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="waittime" data-view="Waittime" data-title="Airport Wait Time"></div>
</li>
<h1 class="title" data-bind="title"></h1>
<h2 class="checkpoint" data-bind="checkpoint"></h2>
<h3 class="waittime" data-bind="waittime | prepend prefix | append suffix"></h3>
<p class="change-rate">
<i class="icon-time"></i><span data-bind="status"></span>
</p>
<p class="more-info" data-bind="info | raw"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'HTTParty'
require 'json'
require 'crack'
airport_code = 'syr'
wait_time_values = ["No Wait", "1-10 minutes", "11-20 minutes", "21-30 minutes", "31+ minutes"]
airports_resource = 'http://www.tsa.gov/data/apcp.xml'
airport_checkpoint_resource = 'http://apps.tsa.dhs.gov/MyTSAWebService/GetWaitTimes.ashx'
airport_name = airport_code
SCHEDULER.every '60s', :first_in => 0 do |job|
airport_checkpoint_waittimes = []
output = []
airports_resource_response = HTTParty.get(airports_resource)
airports_resource_xml = Crack::XML.parse(airports_resource_response.body)
airports_resource_json = Crack::JSON.parse(airports_resource_xml.to_json)
airports_resource_json['airports']['airport'].each do |airport|
if airport['shortcode'] == airport_code.upcase
airport_name = airport['name']
# Stupidness in JSON convesion.. SHould always be array
if !airport['checkpoints']['checkpoint'].kind_of?(Array)
airport['checkpoints']['checkpoint'] = [airport['checkpoints']['checkpoint']]
end
# Airport Checkpoints
airport['checkpoints']['checkpoint'].each do |checkpoint|
# puts "Getting Checkpoints"
# puts "Checkpoint Id: " + checkpoint['id']
# puts "Checkpoint Name: " + checkpoint['longname']
airport_checkpoint_resouce_response = HTTParty.get(airport_checkpoint_resource, { :query => { :ap => airport_code, :output => 'json'} })
airport_checkpoint_resouce_json = JSON.parse(airport_checkpoint_resouce_response.body)
airport_checkpoint_resouce_json['WaitTimes'].each do |waittime|
if waittime['CheckpointIndex'] == checkpoint['id']
# puts "Wait Time " + waittime['WaitTimeIndex'] + " minutes"
# puts "Updated: " + waittime["Created_Datetime"] #9/2/2013 2:24:33 AM
#
checkpoint_last_updated_at = DateTime.strptime(waittime["Created_Datetime"], '%m/%d/%Y %H:%M:%S %p')
if checkpoint_last_updated_at.to_date == Date.today
# puts waittime["Created_Datetime"] + " Is TODAY!"
airport_checkpoint_waittimes << {
:id => checkpoint["id"],
:name => checkpoint["longname"],
:wait_time => waittime['WaitTimeIndex'],
:updated_at => checkpoint_last_updated_at
}
end
end
end
end
end
end
# Create groups of checkpoints
groups = Hash.new{|h,k| h[k] = [] }
airport_checkpoint_waittimes.each {|checkpoint| groups[checkpoint[:id]] << checkpoint }
# parse checkpoints into new hash
groups.each do |group, data|
data.sort_by!{ |c| c[:updated_at].to_s.to_i}
if data.size > 1
if data[0][:wait_time] < data[1][:wait_time]
time_status = "decraseing"
elsif data[0][:wait_time] == data[1][:wait_time]
time_status = "holding steady"
else
time_status = "increasing"
end
output << {
:id => data[0][:id],
:name => data[0][:name],
:wait_time => wait_time_values[(data[0][:wait_time].to_i) - 1],
:time_status => time_status,
:update => data[0][:updated_at]
}
else
output << {
:id => data[0][:id],
:name => data[0][:name],
:wait_time => wait_time_values[(data[0][:wait_time].to_i) - 1],
:time_status => nil,
:update => data[0][:updated_at]
}
end
end
if output.empty?
send_event('waittime', {
title: airport_name,
checkpoint: "No Wait times have been reported",
waittime: "",
status: "",
info: data[0][:updated_at].strftime("Last TSA update: %m/%d/%Y at %I:%M%p")
})
else
output.cycle do |o|
send_event('waittime', {
title: airport_name,
checkpoint: o[:name],
waittime: o[:wait_time],
status: "Wait time is " + o[:time_status],
info: o[:update].strftime("Last TSA update: %m/%d/%Y at %I:%M%p")
})
sleep(60/output.size)
end
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #47bbb3;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-waittime styles
// ----------------------------------------------------------------------------
.widget-waittime {
background-color: $background-color;
.title {
color: $title-color;
}
.checkpoint {
color: $value-color;
font-size: 20px;
}
.change-rate {
font-size: 15px;
color: $value-color;
}
.more-info {
color: $moreinfo-color;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
}
@JujharSP
Copy link

JujharSP commented Dec 8, 2025

TSA API is shut down

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