firstrow 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/bin/firstrow +157 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjY5YzFmYjRlN2M3ZjNlNGVhNTVjNTFhYmViOGUxYTg5N2U4N2I5YQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTk2ZDcyN2QxMzFmMjkxMmJjMDRkYzgxNGVhNDI3NDVkYTgzNGFhZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NTg0MzRkNmNhNDQwMjM0NWNiNjE0ZThmZmZiMTRkYWIxMzNlMGE2NDAxZDFl
|
10
|
+
MzYzNjk0MjhlOThmY2U2ZWZiYzUwY2I4NTc2YmI0NjgwYjI4NWVmOGNkMjEz
|
11
|
+
ODU2MjkxMzRkMzcyZjBhYmY3YTk4NGU2YjQ1NmIzNDY5Nzk5MWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2E1ZTUxMTYwMjYyZGI3NDBlZjRjY2VjNTljYTYwMmJkMDg2MzM0NWI2YjU0
|
14
|
+
ODFlODA0ZjA1OTMxOThkMTgyZDk0ZDUzY2MzYmM1ZGE0ZjZkNWFjNTJjNzUz
|
15
|
+
ODk1OTQ2NzVjMTQwZmJjZmNkMjk2MjJlYWUzYmIyZjk1OTk2NmY=
|
data/bin/firstrow
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'nokogiri'
|
6
|
+
require 'paint'
|
7
|
+
|
8
|
+
def open(url)
|
9
|
+
Net::HTTP.get(URI.parse(url))
|
10
|
+
end
|
11
|
+
|
12
|
+
$object = [nil]
|
13
|
+
|
14
|
+
def get(i); return false if $object[i].nil?; $object[i]; end
|
15
|
+
def set(object); $object.push(object); $object.length - 1; end
|
16
|
+
|
17
|
+
def launch_match(id)
|
18
|
+
match = get(id)
|
19
|
+
|
20
|
+
if match[:links].length == 0
|
21
|
+
puts Paint["No links found", :red]
|
22
|
+
return
|
23
|
+
elsif match[:links].length == 1
|
24
|
+
link = match[:links][0]
|
25
|
+
else
|
26
|
+
match_input = ""
|
27
|
+
while match_input == ""
|
28
|
+
print Paint["Enter stream number to watch (Enter between stream 1-#{match[:links].length}): ", "EDD9AA"]
|
29
|
+
match_input = gets.chomp
|
30
|
+
match_input = "" if match_input.to_i.abs == 0 or match[:links][match_input.to_i.abs - 1].nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
link = match[:links][match_input.to_i.abs - 1]
|
34
|
+
end
|
35
|
+
|
36
|
+
print Paint["Opening stream in browser... ", "FFFFFF"]
|
37
|
+
page_content = open(link)
|
38
|
+
page_iframe = Nokogiri::HTML(page_content).css('iframe').first.attr('src')
|
39
|
+
|
40
|
+
if not page_iframe.nil?
|
41
|
+
`chrome '#{page_iframe}'`
|
42
|
+
else
|
43
|
+
`chrome '#{link}'`
|
44
|
+
end
|
45
|
+
|
46
|
+
print Paint["Done. ", "FFFFFF"]
|
47
|
+
puts
|
48
|
+
end
|
49
|
+
|
50
|
+
# Default arguments
|
51
|
+
show_all = false
|
52
|
+
|
53
|
+
# Check arguments
|
54
|
+
ARGV.each do |argument|
|
55
|
+
show_all = true if argument == "--all"
|
56
|
+
end
|
57
|
+
|
58
|
+
puts Paint["Getting all matches from First Row Sports..", "EDD9AA"]
|
59
|
+
|
60
|
+
page_content = open('http://www.firstrow.org/')
|
61
|
+
page_parsed = Nokogiri::HTML(page_content)
|
62
|
+
|
63
|
+
page_parsed.css('td.accordion.greybg').each do |match|
|
64
|
+
raw_html = match.to_s
|
65
|
+
|
66
|
+
# What time does the match start?
|
67
|
+
start_time = Time.at(match.css('span.dt').first.attr("class").gsub('dt', '').strip.to_i + 60**2)
|
68
|
+
start_hour = start_time.strftime("%H").to_i # Hour number. Example: 14
|
69
|
+
start_time = start_time.strftime("%H:%M %Z") # Parse into readable time.
|
70
|
+
|
71
|
+
# Don't show all.
|
72
|
+
if (show_all == false and start_hour > Time.now.hour + 1) or (start_hour <= Time.now.hour - 2)
|
73
|
+
next
|
74
|
+
end
|
75
|
+
|
76
|
+
# Match name. Example: Real Madrid v Barcelona
|
77
|
+
match_name = match.css('h4 a').first.content.gsub(' - ', ' v ').strip
|
78
|
+
|
79
|
+
# Cool stuff. Replace famous teams with their national colours.
|
80
|
+
colors = {
|
81
|
+
"Arsenal" => "ec2832",
|
82
|
+
"Everton FC" => "10459a"
|
83
|
+
}
|
84
|
+
color_set = false
|
85
|
+
colors.each do |name, color|
|
86
|
+
if match_name.include?(name)
|
87
|
+
color_set = true
|
88
|
+
first_team, second_team = match_name.split(' v ')
|
89
|
+
if first_team == name
|
90
|
+
match_name = Paint[name.strip, color] + Paint[" v " + second_team.strip, "FFFFFF"]
|
91
|
+
else
|
92
|
+
match_name = Paint[first_team.strip + " v ", "FFFFFF"] + Paint[name.strip, color]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
if color_set == false
|
98
|
+
match_name = Paint[match_name, "FFFFFF"]
|
99
|
+
end
|
100
|
+
|
101
|
+
# Links to the matches
|
102
|
+
links = []
|
103
|
+
match.css('.module-desc a').each do |link|
|
104
|
+
# Include match links
|
105
|
+
links.push(link.attr("href")) if link.attr("href").include?("firstrow")
|
106
|
+
end
|
107
|
+
|
108
|
+
# Set colour.
|
109
|
+
match_color = (start_hour >= 12) ? "6CB809" : "167FC9"
|
110
|
+
|
111
|
+
# Insert into temporary database.
|
112
|
+
match_id = set({
|
113
|
+
:name => match_name,
|
114
|
+
:time => start_time,
|
115
|
+
:linkcount => links.length,
|
116
|
+
:links => links
|
117
|
+
})
|
118
|
+
|
119
|
+
match_text = "(Match #{match_id}) "
|
120
|
+
match_text += " " if match_id < 10
|
121
|
+
start_text = "#{start_time} "
|
122
|
+
|
123
|
+
str_count = (match_text + start_text).length
|
124
|
+
str_spaces = ""
|
125
|
+
if str_count < 18
|
126
|
+
(0..18-str_count).each { |space| str_spaces += " " }
|
127
|
+
end
|
128
|
+
|
129
|
+
puts Paint[match_text, "EDD9AA"] + Paint[start_text, :bold, match_color] + str_spaces + match_name
|
130
|
+
end
|
131
|
+
|
132
|
+
# Get input
|
133
|
+
puts ""
|
134
|
+
print Paint["Enter match number to watch: #", "EDD9AA"]
|
135
|
+
match_input = gets.chomp
|
136
|
+
|
137
|
+
# No input.
|
138
|
+
if match_input == ""
|
139
|
+
puts Paint["No match found with that number.", :red]
|
140
|
+
abort
|
141
|
+
end
|
142
|
+
|
143
|
+
# Avoid String-Integer issues.
|
144
|
+
begin
|
145
|
+
match_input = match_input.to_i.abs
|
146
|
+
rescue TypeError
|
147
|
+
puts Paint["Invalid match number.", :red]
|
148
|
+
abort
|
149
|
+
end
|
150
|
+
|
151
|
+
# Right let's sort this.
|
152
|
+
if get(match_input)
|
153
|
+
launch_match(match_input)
|
154
|
+
else
|
155
|
+
puts Paint["No match found.", :red]
|
156
|
+
abort
|
157
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: firstrow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bilawal Hameed
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: paint
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A simple command-line gem provides a simple UI for watching football
|
42
|
+
matches via FirstRowSports.
|
43
|
+
email: me@bilaw.al
|
44
|
+
executables:
|
45
|
+
- firstrow
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- bin/firstrow
|
50
|
+
homepage: http://rubygems.org/gems/firstrow
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message: ! '>> Firstrow successfully setup. To get started - simply call
|
55
|
+
the `firstrow` command :)'
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.1.9
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Beautiful command line access to live football matches.
|
75
|
+
test_files: []
|