1
1
module BnetScraper
2
2
module Starcraft2
3
+ # This pulls achievement information for an account. Note that currently only returns the overall achievements,
4
+ # not the in-depth, by-category achievement information.
5
+ #
6
+ # scraper = BnetScraper::Starcraft2::AchievementScraper.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/')
7
+ # scraper.scrape
8
+ # # => {
9
+ # recent: [
10
+ # { title: 'Blink of an Eye', description: 'Complete round 24 in "Starcraft Master" without losing any stalkers', earned: '3/5/2012' },
11
+ # { title: 'Whack-a-Roach', description: 'Complete round 9 in "Starcraft Master" in under 45 seconds', earned: '3/5/2012' },
12
+ # { title: 'Safe Zone', description: 'Complete round 8 in "Starcraft Master" without losing any stalkers', earned: '3/5/2012' },
13
+ # { title: 'Starcraft Master', description: 'Complete all 30 rounds in "Starcraft Master"', earned: '3/5/2012' },
14
+ # { title: 'Starcraft Expert', description: 'Complete any 25 rounds in "Starcraft Master"', earned: '3/5/2012' },
15
+ # { title: 'Starcraft Apprentice', description: 'Complete any 20 rounds in "Starcraft Master"', earned: '3/5/2012' }
16
+ # ],
17
+ # showcase: [
18
+ # { title: 'Hot Shot', description: 'Finish a Qualification Round with an undefeated record.' },
19
+ # { title: 'Starcraft Master', description: 'Complete all rounds in "Starcraft Master"' },
20
+ # { title: 'Team Protoss 500', description: 'Win 500 team league matches as Protoss' },
21
+ # { title: 'Night of the Living III', description: 'Survive 15 Infested Horde Attacks in the "Night 2 Die" mode of the "Left 2 Die" scenario.' },
22
+ # { title: 'Team Top 100 Diamond', description: 'Finish a Season in Team Diamond Division' }
23
+ #
24
+ # ],
25
+ # progress: {
26
+ # liberty_campaign: '1580',
27
+ # exploration: '480',
28
+ # custom_game: '330',
29
+ # cooperative: '660',
30
+ # quick_match: '170'
31
+ # }
32
+ # }
3
33
class AchievementScraper < BaseScraper
4
34
attr_reader :recent , :progress , :showcase , :response
5
35
@@ -11,10 +41,12 @@ def scrape
11
41
output
12
42
end
13
43
44
+ # retrieves the account's achievements overview page HTML for scraping
14
45
def get_response
15
46
@response = Nokogiri ::HTML ( open ( profile_url +"achievements/" ) )
16
47
end
17
48
49
+ # scrapes the recent achievements from the account's achievements overview page
18
50
def scrape_recent
19
51
@recent = [ ]
20
52
6 . times do |num |
@@ -31,6 +63,7 @@ def scrape_recent
31
63
@recent
32
64
end
33
65
66
+ # scrapes the progress of each achievement category from the account's achievements overview page
34
67
def scrape_progress
35
68
progress_ach = response . css ( "#progress-module .achievements-progress:nth(2) span" )
36
69
@progress = {
@@ -42,6 +75,7 @@ def scrape_progress
42
75
}
43
76
end
44
77
78
+ # scrapes the showcase achievements from the account's achievements overview page
45
79
def scrape_showcase
46
80
@showcase = response . css ( "#showcase-module .progress-tile" ) . map do |achievement |
47
81
hsh = { title : achievement . css ( '.tooltip-title' ) . inner_text . strip }
0 commit comments