tsadatalite 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/tsadatalite.rb +81 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODFlNGJhNzQwYWNmMDhlMmJhOTJiMTI3MWFmOTcwZmU2MzUwMmRhNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjAzNjVkMTFkZjg0MGRkNzcwMmFkMjVkNDgwMjViNjU1Y2FkNTJlNQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Mzk3ZjI1OWM0YWFjMWViMDQwY2RmNGU2YTgyZDdlMGQzY2UzYzE4M2E3M2I2
|
10
|
+
YWZjM2I1NDg4NTk1ZjQ4YzZlODhlNTRmNTk5Zjc1ZmVmMDRiMDAwZWUxZjU5
|
11
|
+
NTAyZTkwZWEwMWQ5MWI4N2YxZWNlZDliODZiNTRjYTk0MmUzMDI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODFjMGE0M2NjY2RkODY0ZDZlZjIzNjI2NTk3MTQ5MTdhZTdiMWVjNWI2NDY3
|
14
|
+
MTI4ZTA5MTY4YzFjNDMxMjkwODgxZWI4NDQ2OTU2ZjllNDI0OWY5YWE2MjM0
|
15
|
+
MjM4MjgyYTQyZTAxZWQzMjQ0MmJjM2M0OTIyMTQwYjUwOTEwNzA=
|
data/lib/tsadatalite.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class TSAdata
|
6
|
+
attr_reader :airportname,:checkpoints
|
7
|
+
|
8
|
+
def initialize airportcode
|
9
|
+
xml_airport_data = open('http://www.tsa.gov/data/apcp.xml') {|f| f.read}
|
10
|
+
ng_airport_data = Nokogiri::XML(xml_airport_data)
|
11
|
+
|
12
|
+
airport = ng_airport_data.xpath("//airport[shortcode='#{airportcode}']").at_xpath("name")
|
13
|
+
|
14
|
+
raise "Invalid Airport" if airport.nil?
|
15
|
+
|
16
|
+
@airportname = airport.text
|
17
|
+
|
18
|
+
@checkpoints = {}
|
19
|
+
ng_airport_data.xpath("//airport[shortcode='#{airportcode}']/checkpoints/checkpoint").each do |node|
|
20
|
+
@checkpoints[node.at_xpath("id").text.to_i]=node.at_xpath("longname").text
|
21
|
+
end
|
22
|
+
|
23
|
+
waittimesurl = "http://apps.tsa.dhs.gov/MyTSAWebService/GetWaitTimes.ashx?ap=#{airportcode}"
|
24
|
+
|
25
|
+
begin
|
26
|
+
data = Net::HTTP.get_response(URI.parse(waittimesurl)).body
|
27
|
+
rescue
|
28
|
+
print "connection error"
|
29
|
+
end
|
30
|
+
|
31
|
+
wait_data = Nokogiri::XML(data)
|
32
|
+
|
33
|
+
@waittimes = []
|
34
|
+
|
35
|
+
wait_data.xpath("//WaitTimes").each do |node|
|
36
|
+
a = {}
|
37
|
+
a[:checkpoint] = @checkpoints[node.at_xpath("CheckpointIndex").text.to_i]
|
38
|
+
a[:wait] = node.at_xpath("WaitTimeIndex").text.to_i
|
39
|
+
a[:date] = Date.rfc3339(node.at_xpath("Created_Datetime").text)
|
40
|
+
@waittimes << a unless a[:checkpoint].nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
@waittimes.sort_by! {|hash| hash[:date]}
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def recentwaits
|
48
|
+
recentwaits = {}
|
49
|
+
@waittimes.each do |waithash|
|
50
|
+
recentwaits[waithash[:checkpoint]] = waithash[:wait]
|
51
|
+
end
|
52
|
+
recentwaits
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
class TSAreport
|
58
|
+
attr_reader :airport_report
|
59
|
+
|
60
|
+
def initialize airports
|
61
|
+
@airport_report = {}
|
62
|
+
airports.each do |airport|
|
63
|
+
current_airport_data = TSAdata.new(airport)
|
64
|
+
@airport_report[airport.to_sym] = [current_airport_data.airportname,current_airport_data.recentwaits]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def writereport filename
|
69
|
+
f = File.open(filename,'w')
|
70
|
+
f.puts "************ AIRPORT SECURITY CHECKPOINT WAIT REPORT ************"
|
71
|
+
f.puts ""
|
72
|
+
@airport_report.each do |shortcode, array|
|
73
|
+
f.puts shortcode.to_s + " / " + array[0]+":"
|
74
|
+
array[1].each do |checkpoint,wait|
|
75
|
+
minstring = (wait == 1) ? " minute" : " minutes"
|
76
|
+
f.puts " " + checkpoint + ": " + wait.to_s + minstring
|
77
|
+
end
|
78
|
+
end
|
79
|
+
f.close
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tsadatalite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Kostojohn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Accesses airport security checkpoint waitimes from TSA
|
14
|
+
email: skostojohn@hotmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/tsadatalite.rb
|
20
|
+
homepage: http://rubygems.org/gems/tsadatalite
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Simple gem to pull data from TSA's website
|
44
|
+
test_files: []
|