Skip to content

Commit f036721

Browse files
committed
Uses new battle.net profile stats page
1 parent ed834cc commit f036721

File tree

4 files changed

+163
-276
lines changed

4 files changed

+163
-276
lines changed

lib/bnet_scraper/starcraft2/profile_scraper.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module Starcraft2
2121
# ]
2222
# }
2323
class ProfileScraper < BaseScraper
24-
attr_reader :achievement_points, :wins, :race, :leagues
24+
attr_reader :achievement_points, :career_games, :race, :leagues, :most_played,
25+
:games_this_season
2526
def scrape
2627
get_profile_data
2728
get_league_list
@@ -35,12 +36,12 @@ def get_profile_data
3536
if response.success?
3637
html = Nokogiri::HTML(response.body)
3738

38-
if race_div = html.css("#season-snapshot .module-footer a").first()
39-
@race = race_div.inner_html()
40-
end
4139

42-
@wins = html.css("#career-stats h2").inner_html()
40+
@race = html.css(".stat-block:nth-child(4) h2").inner_html()
4341
@achievement_points = html.css("#profile-header h3").inner_html()
42+
@career_games = html.css(".stat-block:nth-child(3) h2").inner_html()
43+
@most_played = html.css(".stat-block:nth-child(2) h2").inner_html()
44+
@games_this_season = html.css(".stat-block:nth-child(1) h2").inner_html()
4445
else
4546
raise BnetScraper::InvalidProfileError
4647
end
@@ -70,7 +71,9 @@ def output
7071
account: @account,
7172
bnet_index: @bnet_index,
7273
race: @race,
73-
wins: @wins,
74+
career_games: @career_games,
75+
games_this_season: @games_this_season,
76+
most_played: @most_played,
7477
achievement_points: @achievement_points,
7578
leagues: @leagues
7679
}

spec/starcraft2/profile_scraper_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
it 'should set the race, wins, and achievements attributes' do
1313
subject.instance_variable_get(:@race).should be_nil
1414
subject.instance_variable_get(:@achievement_points).should be_nil
15-
subject.instance_variable_get(:@wins).should be_nil
1615

1716
subject.get_profile_data
1817

1918
subject.instance_variable_get(:@race).should == 'Protoss'
20-
subject.instance_variable_get(:@achievement_points).should == '3630'
21-
subject.instance_variable_get(:@wins).should == '684'
19+
subject.instance_variable_get(:@achievement_points).should == '3660'
2220
end
2321
end
2422

@@ -61,7 +59,7 @@
6159
end
6260

6361
it 'should set nil race' do
64-
scraper.race.should be_nil
62+
scraper.race.should == ''
6563
end
6664

6765
it 'should have an empty array of leagues' do
@@ -77,8 +75,10 @@
7775
account: 'Demon',
7876
bnet_index: 1,
7977
race: 'Protoss',
80-
wins: '684',
81-
achievement_points: '3630',
78+
career_games: '1568',
79+
games_this_season: '0',
80+
most_played: '4v4',
81+
achievement_points: '3660',
8282
leagues: [
8383
{
8484
name: "1v1 Platinum Rank 95",
@@ -143,7 +143,7 @@
143143
]
144144
}
145145

146-
subject.output.should == { bnet_id: '2377239', account: 'Demon', bnet_index: 1, race: nil, wins: nil, achievement_points: nil, leagues: nil }
146+
subject.output.should == { bnet_id: '2377239', account: 'Demon', bnet_index: 1, race: nil, career_games: nil, games_this_season: nil, most_played: nil, achievement_points: nil, leagues: nil }
147147
subject.scrape
148148
subject.output.should == expected
149149
end

spec/starcraft2_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
:account=>"Demon",
99
:bnet_index=>1,
1010
:race=>"Protoss",
11-
:wins=>"684",
12-
:achievement_points=>"3630",
11+
:career_games => '1568',
12+
:games_this_season => '0',
13+
:most_played => '4v4',
14+
:achievement_points=>"3660",
1315
:leagues=>[
1416
{:season=>"6", :size=>"4v4", :name=>"Aleksander Pepper", :division=>"Diamond", :random=>false, :bnet_id=>"2377239", :account=>"Demon"},
1517
{:season=>"6", :size=>"4v4", :name=>"Aleksander Pepper", :division=>"Diamond", :random=>false, :bnet_id=>"2377239", :account=>"Demon"},

0 commit comments

Comments
 (0)