NBA_info 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 745d4057fa3d17e96d16f192a21a5ff22f9cb8e3
4
- data.tar.gz: 027a55450f5a17b35817894349f013c9c8935fa7
3
+ metadata.gz: 9959ed116b23cb1e9a01da32b67eee5db01d1a86
4
+ data.tar.gz: 3fdce1160071820a78f16bcdc950b7d29d71989d
5
5
  SHA512:
6
- metadata.gz: 07a25bd876280fc9ee8a25bd3ea2a06676b459847b9ce3bce31a92e34da73b47165f95f34414464925bd1d8e4765209cfa733ced6c4e9a8df7626d24405d1321
7
- data.tar.gz: ca61248a608f8a2db7361b70409c51a1da067f9fecf76a1c8ed66f35191b04eac3defd3df3bd27c7ee1b8612caea1099c3e2b0c2dc0ee4471c175be7c9a9a4fa
6
+ metadata.gz: 1e05228ab75582d6ec0fc346fe1ad4aebe8fedbc0a7331a7216d78490c0aa5d96db3ffaf573eca20bc6c79511b308af3008c83e289d68038c232954592871896
7
+ data.tar.gz: 120529b73140814b5d75cca84741ead1b813ae9bad898cc0de8c07fa8b8fd972025e829aceae07351c0a0e1cbd934b8cd2a1d67766778a710d4e56a8c72cd7be
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ mini_portile (0.6.0)
5
+ minitest (5.4.2)
6
+ minitest-rg (5.1.0)
7
+ minitest (~> 5.0)
8
+ nokogiri (1.6.3.1)
9
+ mini_portile (= 0.6.0)
10
+ rake (10.1.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ minitest
17
+ minitest-rg
18
+ nokogiri
19
+ rake
Binary file
data/bin/application.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # require '../lib/NBA_info/NBA_info_ex.rb'
2
3
  require 'NBA_info'
3
- #require '../lib/NBA_info/NBA_info_ex.rb'
4
- sam= Scraper.new
5
- puts "Enter 1 to see starting lineup today, enter 2 to see any player's profile you want."
4
+
5
+ sam = Scraper.new
6
+ puts "Enter 1 to see starting lineup today, enter 2 to see any player's "\
7
+ 'profile you want.'
8
+
6
9
  control = gets.chomp
7
10
  control = control.to_i
8
11
 
@@ -12,18 +15,20 @@ if control == 2
12
15
  name.downcase!
13
16
  name.gsub!(' ', '_')
14
17
  sean = sam.profile(name)[0]
15
- sean.each {
16
- |key, value| puts "#{key} : #{value}"
17
- }
18
+ sean.each { |key, value| puts "#{key} : #{value}" }
18
19
  elsif control == 1
19
20
  po = sam.game[0]
20
21
  w = sam.game[1]
22
+ s = sam.game[2]
21
23
  po.each do |key, value|
22
- puts "#{key}\t#{value}"
23
- if key.include? 'PM' || 'AM'
24
- 5.times { puts w.shift }
24
+ puts "#{key}\t#{value}\n"
25
+ if key.include? 'PM'
26
+ 5.times { puts s.shift }
27
+ puts "\n"
25
28
  else
26
- 3.times { puts w.shift }
29
+ 1.times { puts w.shift }
30
+ 3.times { puts s.shift }
31
+ puts "\n"
27
32
  end
28
33
  end
29
34
  end
@@ -2,33 +2,46 @@ require 'open-uri'
2
2
  require 'nokogiri'
3
3
  # this is a class
4
4
  class Scraper
5
-
6
-
7
5
  def game
8
- x, y, z, w, team_1 = [], [], [], [], []
6
+ x, y, z, w, team_1, start_line_up, s = [], [], [], [], [], [], []
7
+ count = 1
9
8
 
10
9
  doc = Nokogiri.HTML(open('http://scores.espn.go.com/nba/scoreboard'))
11
10
 
12
11
  time = doc.xpath("//div[@class='game-status']//p")
13
- time.each { |times| x << times.text }
14
- team = doc.xpath("//div[@class='team-capsule']//a")
12
+ time.each do |times|
13
+ if times.text == 'Final'
14
+ x << times.text + ' ' + count.to_s
15
+ count += 1
16
+ else
17
+ x << times.text
18
+ end
19
+ end
20
+ team = doc.xpath("//div[@class='team-capsule']//span")
15
21
  team.each { |teams| y << teams.text }
22
+ score = doc.xpath("//div[@class='mod-content']//ul[@class='score']\
23
+ //li[@class='finalScore']")
24
+ score.each { |scores| team_1 << scores.text }
16
25
  player = doc.xpath("//div[@style='display: block']\
17
26
  //table[@class='game-stat-overview']//tbody//tr//td")
18
- player.each { |p| team_1 << p.text }
27
+ player.each { |p| start_line_up << p.text }
19
28
 
20
- for i in 0..(y.size) / 2 - 1
29
+ (y.size / 2 - 1).times do |i|
21
30
  z << y[i * 2] + ' v.s ' + y[i * 2 + 1]
22
31
  end
23
32
 
24
- for i in 0..(team_1.size) / 5 - 1
25
- w << team_1[i * 5] + "\t" + "#{team_1[i * 5 + 1]} #{team_1[i * 5 + 2]}" + \
26
- ' v.s ' + "#{team_1[i * 5 + 3]} #{team_1[i * 5 + 4]}"
33
+ (team_1.size / 2 - 1).times do |i|
34
+ w << team_1[i * 2] + ' v.s ' + team_1[i * 2 + 1]
27
35
  end
28
36
 
29
- schedule_table_upcoming = Hash[x.zip(z)]
30
- [schedule_table_upcoming, w]
37
+ (start_line_up.size / 5 - 1).times do |i|
38
+ s << start_line_up[i * 5] + "\t" + "#{start_line_up[i * 5 + 1]} "\
39
+ "#{start_line_up[i * 5 + 2]}" + ' v.s ' + "#{start_line_up[i * 5 + 3]} "\
40
+ "#{start_line_up[i * 5 + 4]}"
41
+ end
31
42
 
43
+ schedule_table_upcoming = Hash[x.zip(z)]
44
+ [schedule_table_upcoming, w, s]
32
45
  end
33
46
 
34
47
  def profile(name)
@@ -36,6 +49,12 @@ class Scraper
36
49
  data = %w('PTS' 'REB' 'AST' 'PIE')
37
50
  web_data_player = 'http://origin.nba.com/playerfile/'
38
51
  web_data_player += name
52
+ begin
53
+ open(web_data_player)
54
+ rescue
55
+ puts 'Player not found, please input the whole right name.'
56
+ exit
57
+ end
39
58
  doc1 = Nokogiri.HTML(open(web_data_player))
40
59
  profile = doc1.xpath("//div[@class='sponsor-branding']\
41
60
  //tr[@class='stats text-shadow']//td")
@@ -43,5 +62,4 @@ class Scraper
43
62
  player_profile = Hash[data.zip(f)]
44
63
  [player_profile, f]
45
64
  end
46
-
47
65
  end
@@ -1,4 +1,4 @@
1
1
  module NBA_INFO
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  DATE = '2014-10-24'
4
4
  end
data/spec/test.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/rg'
3
- <<<<<<< HEAD
4
3
  require '../lib/NBA_info/NBA_info_ex.rb'
5
4
 
6
5
  describe 'Do some test' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: NBA_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - poweihuang
@@ -49,8 +49,9 @@ extra_rdoc_files: []
49
49
  files:
50
50
  - ".travis.yml"
51
51
  - Gemfile
52
+ - Gemfile.lock
52
53
  - LICENSE
53
- - NBA_info-0.1.1.gem
54
+ - NBA_info-0.1.2.gem
54
55
  - NBA_info.gemspec
55
56
  - README.md
56
57
  - Rakefile
data/NBA_info-0.1.1.gem DELETED
Binary file