tubestatus 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/tubestatus +2 -0
- data/lib/tubestatus.rb +91 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e98c987f6ece283e970c314264b35a359ec46d72
|
4
|
+
data.tar.gz: e0eab7098df9d11821d9f2ff70c85319040ddf5e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 968c71ca36872640e9864ce97fa7a6bfb28a667a715fe56f5272738036af629285a5795cb452a4024c1026497ab297b92e025e8c7607a983a5bf16a4eb784f16
|
7
|
+
data.tar.gz: bd7f1b578b95b5f4dc333d19e22eeddbdb7483fdb1af44fc43bdc0e385a3f7efea4d0c5c4040ff6ae67e6228728ff345084dd8ded9c24658be2dddad38fd476f
|
data/bin/tubestatus
ADDED
data/lib/tubestatus.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "optparse"
|
3
|
+
require "open-uri"
|
4
|
+
require 'net/http'
|
5
|
+
require "json"
|
6
|
+
require 'text-table'
|
7
|
+
require 'colorize'
|
8
|
+
#API provided by tubeupdates.com
|
9
|
+
|
10
|
+
def getAll(url)
|
11
|
+
exchanges = []
|
12
|
+
begin
|
13
|
+
open(url) do |d|
|
14
|
+
json = JSON.parse(d.read)
|
15
|
+
json.each do |a|
|
16
|
+
exchanges << a
|
17
|
+
end
|
18
|
+
end
|
19
|
+
return true, exchanges
|
20
|
+
end
|
21
|
+
rescue SocketError => e
|
22
|
+
return false, "Could not connect to the API"
|
23
|
+
end
|
24
|
+
|
25
|
+
def getLine(url, symbol)
|
26
|
+
begin
|
27
|
+
open(url) do |d|
|
28
|
+
json = JSON.parse(d.read)
|
29
|
+
json.each do |a|
|
30
|
+
a[1]['lines'].each do |v|
|
31
|
+
if v['id'] == symbol
|
32
|
+
return true, v
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
return false, "Could not find line. Please use one of the following ID's bakerloo, central, district, docklands, hammersmithcity, jubilee, metropolitan, northern, piccadilly, overground, victoria, waterloocity"
|
37
|
+
end
|
38
|
+
rescue SocketError => e
|
39
|
+
return false, "Could not connect to the API"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
table = Text::Table.new :horizontal_padding => 1,
|
45
|
+
:vertical_boundary => '-',
|
46
|
+
:horizontal_boundary => '|',
|
47
|
+
:boundary_intersection => '-'
|
48
|
+
|
49
|
+
case ARGV[0]
|
50
|
+
when nil
|
51
|
+
info = getAll("http://api.tubeupdates.com/?method=get.status&format=json")
|
52
|
+
#if failed to connect then display the error message
|
53
|
+
if info[0] == false
|
54
|
+
puts info[1]
|
55
|
+
else
|
56
|
+
table.head = ["Line", "Status"]
|
57
|
+
info[1][0][1]["lines"].each_with_index do |lines|
|
58
|
+
status = "%s" % lines["status"].split.map(&:capitalize).join(' ')
|
59
|
+
names = "%s" % lines["name"].gsub("\&", '&')
|
60
|
+
table.rows << [names, status]
|
61
|
+
end
|
62
|
+
puts table.to_s
|
63
|
+
end
|
64
|
+
else
|
65
|
+
|
66
|
+
info = getLine("http://api.tubeupdates.com/?method=get.status&format=json", ARGV[0])
|
67
|
+
|
68
|
+
if info[0] == false
|
69
|
+
puts info[1]
|
70
|
+
else
|
71
|
+
name = info[1]['name'].gsub("\&", '&')
|
72
|
+
status = info[1]['status'].split.map(&:capitalize).join(' ')
|
73
|
+
if status == "Good Service"
|
74
|
+
status = status.green
|
75
|
+
else
|
76
|
+
status = status.red
|
77
|
+
end
|
78
|
+
|
79
|
+
puts "Line: " + name
|
80
|
+
puts "Status: " + status
|
81
|
+
if info[1]['messages'].empty?
|
82
|
+
puts "Messages: None"
|
83
|
+
else
|
84
|
+
puts "Messages: "
|
85
|
+
info[1]['messages'].each do |d|
|
86
|
+
puts d.gsub("\&", '&')
|
87
|
+
puts "\n"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tubestatus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Minesh Mandalia
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Provides London Tube updates in your Terminal
|
14
|
+
email:
|
15
|
+
- minesh@mandalia.me
|
16
|
+
executables:
|
17
|
+
- tubestatus
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/tubestatus
|
22
|
+
- lib/tubestatus.rb
|
23
|
+
homepage: http://mineshmandalia.com/
|
24
|
+
licenses: []
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Tube Status in your Terminal
|
46
|
+
test_files: []
|