bnet_scraper 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  # Changelog!
2
2
 
3
+ ## 0.3.0 (Sep 22 2012)
4
+
5
+ * Adds portrait name scraping to ProfileScraper
6
+
3
7
  ## 0.2.1 (Aug 04 2012)
4
8
 
5
9
  * Adds race condition for profile scraping accounts playing in their first season
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "bnet_scraper"
6
- s.version = "0.2.1"
6
+ s.version = "0.3.0"
7
7
  s.authors = ["Andrew Nordman"]
8
8
  s.email = ["anordman@majorleaguegaming.com"]
9
9
  s.homepage = "https://github.com/agoragames/bnet_scraper/"
@@ -27,6 +27,58 @@ module BnetScraper
27
27
  'tw.battle.net' => 'fea'
28
28
  }
29
29
 
30
+ # The armory uses spritemaps that are sequentially named and have a fixed
31
+ # 6x6 grid. We'll simply use the portrait names, left to right, top to
32
+ # bottom.
33
+ #
34
+ # Note: I couldn't identify the exact names of some of these and instead of
35
+ # guessing, I didn't name them. Some appear in multiple files too, which
36
+ # is odd.
37
+ #
38
+ # I decided th pad the arrays even if there are no images to make various
39
+ # helping functionality (e.g. retrieving position for a name) easier.
40
+ # I've also kept them in 6x6 here for better overview.
41
+ PORTRAITS = [
42
+ # http://eu.battle.net/sc2/static/local-common/images/sc2/portraits/0-75.jpg?v42
43
+ ['Kachinsky', 'Cade', 'Thatcher', 'Hall', 'Tiger Marine', 'Panda Marine',
44
+ 'General Warfield', 'Jim Raynor', 'Arcturus Mengsk', 'Sarah Kerrigan', 'Kate Lockwell', 'Rory Swann',
45
+ 'Egon Stetmann', 'Hill', 'Adjutant', 'Dr. Ariel Hanson', 'Gabriel Tosh', 'Matt Horner',
46
+ # Could not identify in order: Raynor in a Suit? Bullmarine? Nova?
47
+ # Fiery Marine?
48
+ 'Tychus Findlay', 'Zeratul', 'Valerian Mengsk', 'Spectre', '?', '?',
49
+ '?', '?', 'SCV', 'Firebat', 'Vulture', 'Hellion',
50
+ 'Medic', 'Spartan Company', 'Wraith', 'Diamondback', 'Probe', 'Scout'],
51
+
52
+ # http://eu.battle.net/sc2/static/local-common/images/sc2/portraits/1-75.jpg?v42
53
+ # Special Rewards - couldn't identify most of these.
54
+ ['?', '?', '?', '?', '?', 'PanTerran Marine',
55
+ '?', '?', '?', '?', '', '',
56
+ '', '', '', '', '', '',
57
+ '', '', '', '', '', '',
58
+ '', '', '', '', '', '',
59
+ '', '', '', '', '', ''],
60
+
61
+ # http://eu.battle.net/sc2/static/local-common/images/sc2/portraits/2-75.jpg?v42
62
+ ['Ghost', 'Thor', 'Battlecruiser', 'Nova', 'Zealot', 'Stalker',
63
+ 'Phoenix', 'Immortal', 'Void Ray', 'Colossus', 'Carrier', 'Tassadar',
64
+ 'Reaper', 'Sentry', 'Overseer', 'Viking', 'High Templar', 'Mutalisk',
65
+ # Unidentified: Bird? Dog? Robot?
66
+ 'Banshee', 'Hybrid Destroyer', 'Dark Voice', '?', '?', '?',
67
+ # Unidentified: Worgen? Goblin? Chef?
68
+ 'Orian', 'Wolf Marine', 'Murloc Marine', '?', '?', 'Zealot Chef',
69
+ # Unidentified: KISS Marine? Dragon Marine? Dragon? Another Raynor?
70
+ 'Stank', 'Ornatus', '?', '?', '?', '?'],
71
+
72
+ # http://eu.battle.net/sc2/static/local-common/images/sc2/portraits/3-75.jpg?v42
73
+ ['Urun', 'Nyon', 'Executor', 'Mohandar', 'Selendis', 'Artanis',
74
+ 'Drone', 'Infested Colonist', 'Infested Marine', 'Corruptor', 'Aberration', 'Broodlord',
75
+ 'Overmind', 'Leviathan', 'Overlord', 'Hydralisk Marine', "Zer'atai Dark Templar", 'Goliath',
76
+ # Unidentified: Satan Marine?
77
+ 'Lenassa Dark Templar', 'Mira Han', 'Archon', 'Hybrid Reaver', 'Predator', '?',
78
+ 'Zergling', 'Roach', 'Baneling', 'Hydralisk', 'Queen', 'Infestor',
79
+ 'Ultralisk', 'Queen of Blades', 'Marine', 'Marauder', 'Medivac', 'Siege Tank']
80
+ ]
81
+
30
82
  # This is a convenience method that chains calls to ProfileScraper,
31
83
  # followed by a scrape of each league returned in the `leagues` array
32
84
  # in the profile_data. The end result is a fully scraped profile with
@@ -30,7 +30,7 @@ module BnetScraper
30
30
  class ProfileScraper < BaseScraper
31
31
  attr_reader :achievement_points, :career_games, :race, :leagues, :most_played,
32
32
  :games_this_season, :highest_solo_league, :current_solo_league, :highest_team_league,
33
- :current_team_league
33
+ :current_team_league, :portrait
34
34
 
35
35
  def initialize options = {}
36
36
  super
@@ -50,6 +50,16 @@ module BnetScraper
50
50
  if response.success?
51
51
  html = Nokogiri::HTML(response.body)
52
52
 
53
+ # Portraits use spritemaps, so we extract positions and map to
54
+ # PORTRAITS.
55
+ @portrait = begin
56
+ portrait = html.css("#profile-header #portrait span").attr('style').to_s.scan(/url\('(.*?)'\) ([\-\d]+)px ([\-\d]+)px/).flatten
57
+ portrait_map, portrait_size = portrait[0].scan(/(\d)\-(\d+)\.jpg/)[0]
58
+ portrait_position = (((0-portrait[2].to_i) / portrait_size.to_i) * 6) + ((0-portrait[1].to_i) / portrait_size.to_i + 1)
59
+ PORTRAITS[portrait_map.to_i][portrait_position-1]
60
+ rescue
61
+ nil
62
+ end
53
63
 
54
64
  @race = html.css(".stat-block:nth-child(4) h2").inner_html()
55
65
  @achievement_points = html.css("#profile-header h3").inner_html()
@@ -118,7 +128,8 @@ module BnetScraper
118
128
  games_this_season: @games_this_season,
119
129
  most_played: @most_played,
120
130
  achievement_points: @achievement_points,
121
- leagues: @leagues
131
+ leagues: @leagues,
132
+ portrait: @portrait
122
133
  }
123
134
  end
124
135
  end
@@ -96,6 +96,7 @@ describe BnetScraper::Starcraft2::ProfileScraper do
96
96
  current_team_league: 'Not Yet Ranked',
97
97
  most_played: '4v4',
98
98
  achievement_points: '3660',
99
+ portrait: 'Mohandar',
99
100
  leagues: [
100
101
  {
101
102
  name: "1v1 Platinum Rank 95",
@@ -173,7 +174,8 @@ describe BnetScraper::Starcraft2::ProfileScraper do
173
174
  highest_team_league: nil,
174
175
  current_team_league: nil,
175
176
  achievement_points: nil,
176
- leagues: []
177
+ leagues: [],
178
+ portrait: nil
177
179
  }
178
180
 
179
181
  subject.scrape
@@ -15,7 +15,8 @@ describe BnetScraper::Starcraft2 do
15
15
  :highest_solo_league => 'Platinum',
16
16
  :current_team_league => 'Not Yet Ranked',
17
17
  :highest_team_league => 'Diamond',
18
- :achievement_points=>"3660",
18
+ :achievement_points => '3660',
19
+ :portrait => 'Mohandar',
19
20
  :leagues=>[
20
21
  {:season=>"6", :size=>"4v4", :name=>"Aleksander Pepper", :division=>"Diamond", :random=>false, :bnet_id=>"2377239", :account=>"Demon"},
21
22
  {:season=>"6", :size=>"4v4", :name=>"Aleksander Pepper", :division=>"Diamond", :random=>false, :bnet_id=>"2377239", :account=>"Demon"},
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bnet_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-04 00:00:00.000000000 Z
12
+ date: 2012-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70323869785380 !ruby/object:Gem::Requirement
16
+ requirement: &70190591320380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70323869785380
24
+ version_requirements: *70190591320380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faraday
27
- requirement: &70323869784840 !ruby/object:Gem::Requirement
27
+ requirement: &70190591319800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70323869784840
35
+ version_requirements: *70190591319800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70323869784280 !ruby/object:Gem::Requirement
38
+ requirement: &70190591319280 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70323869784280
46
+ version_requirements: *70190591319280
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70323869783500 !ruby/object:Gem::Requirement
49
+ requirement: &70190591318580 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70323869783500
57
+ version_requirements: *70190591318580
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: fakeweb
60
- requirement: &70323869782080 !ruby/object:Gem::Requirement
60
+ requirement: &70190591317300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70323869782080
68
+ version_requirements: *70190591317300
69
69
  description: BnetScraper is a Nokogiri-based scraper of Battle.net profile information.
70
70
  Currently this only includes Starcraft2.
71
71
  email:
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: 4047051916263475144
130
+ hash: -114027561748751341
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements:
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: 4047051916263475144
139
+ hash: -114027561748751341
140
140
  requirements: []
141
141
  rubyforge_project:
142
142
  rubygems_version: 1.8.17