firstrow 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/bin/firstrow +169 -90
  3. metadata +6 -5
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmQ4YzkzNjk3ZGU1YjE1OWQ3YjlhNTQwNzU5MzVmMjVjMGMxMGI2OQ==
4
+ YTYzMzBkMWQ4MWFiNTdjYjgyNjA2ZWJkYmQ3OTgzYTVjYTNjNmJiMw==
5
5
  data.tar.gz: !binary |-
6
- Zjc3NjhiNmQ0OTBjNDVjYzllOGFhNDc0NDU4ZjMwODQzYTU2N2ZkMQ==
6
+ YjU0ZTZiNjc4NzU0ZGI4NGVjZWU4NTFhNGFjNDUwM2VlMzU4NWNjZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmVmM2U5ZmM3ZGI4MmU1ZGIwYzcwYmE2Zjk1NTc0YTM0MzI0YzFlMGViZTBh
10
- NmE2MDIyMGRhMzA5NmZhMTliN2RhZDBlZDFmNDg5MWE3NmJhYmVmNzYwYThl
11
- OTM4M2VlNTEzNWE4NWI2OTY1NmMwNDU1N2NjYWE1ZjA3MmI0ZmY=
9
+ ZTk3ZTk3NzBlYzkwYjJhNTBlMGU2MzFkZThlOWE2NjBmMDgyZDE2ZGYxZDFh
10
+ NTRhZDkwMmEyMjVhODJjYjExZTE1YTJmZWUxMzVkZTk1ZWUyNjliMzhjNTc5
11
+ NGE0ZTkwZTdiYTIxMjg1YmNkOTJjNzc1Mzc5MzVkNTc0Mjk4ZDE=
12
12
  data.tar.gz: !binary |-
13
- YWEyMWZkNDU4Yjc3ZDgyZjAyZjhkYzMwMTkyMGI3NzM2ZTZlOTE3NDQ2M2Fm
14
- OWNlMjhmYWY3YmU2YjYwYzI2NDQ3NGE4NmNjY2I1MjgyMTNlYTI4NGFmMTNm
15
- OTI2ZGNjYmQwMjA1OWUzYTQ3NTAxYTJjNjk0YjE0MmVmMDYyNGM=
13
+ NTU2OTgxM2ZlZWRjN2RlNGY0YzFlMmJiZDYxNzUwYmU1ZjNmYmY0Yjk5N2Nk
14
+ Mzg4ODMxZDZlODIyNDE3MjcxZTk3MmU4YWFhYjk5YjQwNGY4MDZmZWUzZWJh
15
+ ODY4Mzk4MzVlNjhhN2Y4MGM4Y2MwNjM0ZjVmOWM5MjhhYmQ1ZDU=
@@ -14,7 +14,7 @@ $object = [nil]
14
14
  def get(i); return false if $object[i].nil?; $object[i]; end
15
15
  def set(object); $object.push(object); $object.length - 1; end
16
16
 
17
- def launch_match(id)
17
+ def launch_match(id, shown = 0)
18
18
  match = get(id)
19
19
 
20
20
  if match[:links].length == 0
@@ -25,133 +25,212 @@ def launch_match(id)
25
25
  else
26
26
  match_input = ""
27
27
  while match_input == ""
28
- print Paint["Enter stream number to watch (Enter between stream 1-#{match[:links].length}): ", "EDD9AA"]
28
+
29
+ if shown == 0
30
+ print Paint["Enter stream to watch (Enter between stream 1-#{match[:links].length}): ", match[:color]]
31
+ else
32
+ print Paint["Enter another stream to watch (#{shown+1}-#{match[:links].length} or 'exit'): ", match[:color]]
33
+ end
34
+
35
+
29
36
  match_input = $stdin.gets.chomp
30
- match_input = "" if match_input.to_i.abs == 0 or match[:links][match_input.to_i.abs - 1].nil?
37
+
38
+ return false if match_input.to_i.abs == 0 or match[:links][match_input.to_i.abs - 1].nil?
31
39
  end
32
40
 
33
41
  link = match[:links][match_input.to_i.abs - 1]
34
42
  end
35
43
 
36
- print Paint["Opening stream in browser... ", "FFFFFF"]
44
+ print Paint["Opening in Google Chrome... ", "FFFFFF"]
45
+
37
46
  page_content = open(link)
38
47
  page_iframe = Nokogiri::HTML(page_content).css('iframe').first.attr('src')
39
48
 
40
49
  if not page_iframe.nil?
41
- `chrome '#{page_iframe}'`
50
+ `/usr/bin/open -a "/Applications/Google Chrome.app" '#{page_iframe}'`
42
51
  else
43
- `chrome '#{link}'`
52
+ `/usr/bin/open -a "/Applications/Google Chrome.app" '#{link}'`
44
53
  end
45
54
 
46
55
  print Paint["Done. ", "FFFFFF"]
47
56
  puts
57
+
58
+ launch_match(id, shown + 1)
48
59
  end
49
60
 
50
61
  # Default arguments
51
62
  show_all = false
52
63
 
64
+ # Match type
65
+ match_type = nil
66
+
53
67
  # Check arguments
54
68
  ARGV.each do |argument|
69
+ match_type = argument if ['football', 'soccer', 'amfootball', 'rugby', 'basketball', 'hockey', 'volleyball', 'boxing', 'wrestling', 'fighting', 'tennis', 'motosport', 'baseball', 'handball'].include?(argument)
55
70
  show_all = true if argument == "--all"
56
71
  end
57
72
 
58
- puts Paint["Getting all matches from First Row Sports..", "EDD9AA"]
73
+ list = {
74
+ "football" => "Soccer football",
75
+ "amfootball" => "American football",
76
+ "rugby" => "Rugby",
77
+ "basketball" => "Basketball",
78
+ "hockey" => "Ice Hockey",
79
+ "volleyball" => "Volleyball",
80
+ "boxing" => "Boxing matches",
81
+ "wrestling" => "Wrestling (including WWE/UFC)",
82
+ "tennis" => "Tennis",
83
+ "motosport" => "Motosport racing",
84
+ "baseball" => "Baseball",
85
+ "handball" => "Handball"
86
+ }
87
+
88
+ if match_type.nil?
89
+ puts Paint["Sports available via Firstrow Sports:", "FFFFFF"]
90
+
91
+ list.each do |command, description|
92
+ command += " " * (22 - command.length) if command.length < 22
93
+ puts Paint["firstrow #{command}", "FF3366"] + Paint[" => #{description}", "FFFFFF"]
94
+ end
59
95
 
60
- page_content = open('http://www.firstrow.org/')
61
- page_parsed = Nokogiri::HTML(page_content)
96
+ else
62
97
 
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
98
+ case match_type
99
+ when 'football', 'soccer'
100
+ url = 'http://www.firstrow.org/soccer'
101
+ when 'amfootball'
102
+ url = 'http://www.firstrow.org/amfootball'
103
+ when 'rugby'
104
+ url = 'http://www.firstrow.org/rugby'
105
+ when 'basketball'
106
+ url = 'http://www.firstrow.org/basketball'
107
+ when 'hockey'
108
+ url = 'http://www.firstrow.org/hockey'
109
+ when 'volleyball'
110
+ url = 'http://www.firstrow.org/volleyball'
111
+ when 'boxing', 'wrestling', 'fighting'
112
+ url = 'http://www.firstrow.org/boxing'
113
+ when 'tennis'
114
+ url = 'http://www.firstrow.org/tennis'
115
+ when 'motosport'
116
+ url = 'http://www.firstrow.org/moto_gp'
117
+ when 'baseball'
118
+ url = 'http://www.firstrow.org/baseball'
119
+ when 'handball'
120
+ url = 'http://www.firstrow.org/handball'
121
+ else
122
+ url = 'http://www.firstrow.org/soccer'
74
123
  end
75
124
 
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]
125
+ puts Paint["#{list[match_type]}: Getting all matches from Firstrow..", "FAAB6A"]
126
+
127
+ page_content = open(url)
128
+ page_parsed = Nokogiri::HTML(page_content)
129
+
130
+ page_parsed.css('td.accordion.greybg').each do |match|
131
+ raw_html = match.to_s
132
+
133
+ # What time does the match start?
134
+ start_time = Time.at(match.css('span.dt').first.attr("class").gsub('dt', '').strip.to_i + 60**2)
135
+ start_hour = start_time.strftime("%H").to_i # Hour number. Example: 14
136
+ start_time = start_time.strftime("%H:%M %Z") # Parse into readable time.
137
+
138
+ # Don't show all.
139
+ if (show_all == false and start_hour > Time.now.hour + 1) or (start_hour <= Time.now.hour - 2)
140
+ next
141
+ end
142
+
143
+ # Match name. Example: Real Madrid v Barcelona
144
+ match_name = match.css('h4 a').first.content.gsub(' - ', ' v ').strip
145
+
146
+ # Cool stuff. Replace famous teams with their national colours.
147
+ colors = {
148
+ "Arsenal" => "ec2832",
149
+ "Everton FC" => "10459a"
150
+ }
151
+
152
+ color_set = false
153
+ colors.each do |name, color|
154
+ if match_name.include?(name)
155
+ color_set = true
156
+ first_team, second_team = match_name.split(' v ')
157
+ if first_team == name
158
+ match_name = Paint[name.strip, color] + Paint[" v " + second_team.strip, "FFFFFF"]
159
+ else
160
+ match_name = Paint[first_team.strip + " v ", "FFFFFF"] + Paint[name.strip, color]
161
+ end
93
162
  end
94
163
  end
95
- end
96
164
 
97
- if color_set == false
98
- match_name = Paint[match_name, "FFFFFF"]
99
- end
165
+ if color_set == false
166
+ match_name = Paint[match_name, "FFFFFF"]
167
+ end
100
168
 
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
169
+ # Links to the matches
170
+ links = []
171
+ match.css('.module-desc a').each do |link|
172
+ # Include match links
173
+ links.push(link.attr("href")) if link.attr("href").include?("firstrow")
174
+ end
107
175
 
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 += " " }
176
+ # Set colour.
177
+ match_color = (start_hour >= 12) ? "6CB809" : "167FC9"
178
+
179
+ # Insert into temporary database.
180
+ match_id = set({
181
+ :name => match_name,
182
+ :time => start_time,
183
+ :color => match_color,
184
+ :linkcount => links.length,
185
+ :links => links
186
+ })
187
+
188
+ match_text = "(Match #{match_id}) "
189
+ match_text += " " if match_id < 10
190
+ start_text = "#{start_time} "
191
+
192
+ str_count = (match_text + start_text).length
193
+ str_spaces = ""
194
+ if str_count < 18
195
+ (0..18-str_count).each { |space| str_spaces += " " }
196
+ end
197
+
198
+ puts Paint[match_text, "FAAB6A"] + Paint[start_text, :bold, match_color] + str_spaces + match_name
127
199
  end
128
200
 
129
- puts Paint[match_text, "EDD9AA"] + Paint[start_text, :bold, match_color] + str_spaces + match_name
130
- end
201
+ if $object.length <= 1
202
+ puts Paint["No matches currently available.", :red]
203
+ abort
131
204
 
132
- # Get input
133
- puts ""
134
- print Paint["Enter match number to watch: #", "EDD9AA"]
135
- match_input = $stdin.gets.chomp
205
+ else
136
206
 
137
- # No input.
138
- if match_input == ""
139
- puts Paint["No match found with that number.", :red]
140
- abort
141
- end
207
+ # Get input
208
+ puts ""
209
+ print Paint["Enter match number to watch: #", "FAAB6A"]
210
+ match_input = $stdin.gets.chomp
142
211
 
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
212
+ # No input.
213
+ if match_input == ""
214
+ puts Paint["No match found with that number.", :red]
215
+ abort
216
+ end
217
+
218
+ # Avoid String-Integer issues.
219
+ begin
220
+ match_input = match_input.to_i.abs
221
+ rescue TypeError
222
+ puts Paint["Invalid match number.", :red]
223
+ abort
224
+ end
225
+
226
+ # Right let's sort this.
227
+ if get(match_input)
228
+ launch_match(match_input)
229
+ else
230
+ puts Paint["No match found.", :red]
231
+ abort
232
+ end
233
+
234
+ end
150
235
 
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
236
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firstrow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bilawal Hameed
@@ -39,7 +39,8 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: A simple command-line gem provides a simple UI for watching football
42
- matches via FirstRowSports.
42
+ (and other sports such as american football, baseball, handball, rugby, wrestling,
43
+ etc) matches via FirstRowSports.
43
44
  email: me@bilaw.al
44
45
  executables:
45
46
  - firstrow
@@ -51,8 +52,8 @@ homepage: http://rubygems.org/gems/firstrow
51
52
  licenses:
52
53
  - MIT
53
54
  metadata: {}
54
- post_install_message: Boom. You're all setup with FirstRow. To get started - simply
55
- call the `firstrow` command on Terminal :)
55
+ post_install_message: You're using our newest awesome-ist version. Type in the 'firstrow'
56
+ command and select which sport you want to watch. Have fun! -B
56
57
  rdoc_options: []
57
58
  require_paths:
58
59
  - lib
@@ -71,5 +72,5 @@ rubyforge_project:
71
72
  rubygems_version: 2.1.9
72
73
  signing_key:
73
74
  specification_version: 4
74
- summary: Beautiful command line access to live football matches.
75
+ summary: Beautiful command line access to live football (and sports) matches.
75
76
  test_files: []