steam-upcoming 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/steam-upcoming/cli.rb +24 -18
- data/lib/steam-upcoming/game.rb +3 -24
- data/lib/steam-upcoming/scraper.rb +41 -33
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebff50ee91419aa83a61668f696ad91dc901808a
|
4
|
+
data.tar.gz: 373c94cadf069e76f068cf2eadc277920a2f53f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 663ad82a66246991b656f6d25c287564bae04414a0848c0e4798e7a5e3f5efa98c1d6f4727f22ff889b1322d53c36fd8e5ad99be506a7a4b760bbf6f6c33383e
|
7
|
+
data.tar.gz: c43cd262f128b4d2bab0c649165acd69e83b02a658a8aee46947e82749e0b64a596c662ab4ce4e27015e22495eb87d6f1e435da98e1b997a1ec7283586bf6e36
|
data/lib/steam-upcoming/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
1
3
|
class SteamUpcoming::CLI
|
2
4
|
attr_accessor :url
|
3
5
|
|
@@ -8,25 +10,29 @@ class SteamUpcoming::CLI
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def run #run the program
|
11
|
-
puts "\nFetching latest games from the Steam Network...".colorize(:
|
13
|
+
puts "\nFetching latest games from the Steam Network...".colorize(:cyan)
|
12
14
|
make_games(BASE_URL)
|
13
15
|
pages
|
14
16
|
start
|
15
17
|
end
|
16
18
|
|
17
19
|
def make_games(url) #creates the list of game objects from the chosen URL
|
18
|
-
|
19
|
-
SteamUpcoming::Game.create_from_collection(game_array)
|
20
|
+
SteamUpcoming::Scraper.scrape_index_page(url)
|
20
21
|
end
|
21
22
|
|
22
23
|
def pages #generate list of page URLs as an array
|
23
|
-
|
24
|
+
SteamUpcoming::Scraper.create_pages_with_urls(BASE_URL)
|
25
|
+
end
|
26
|
+
|
27
|
+
def number_of_results
|
28
|
+
results = SteamUpcoming::Scraper.get_number_of_results(BASE_URL)
|
24
29
|
end
|
25
30
|
|
26
31
|
def change_page #allow the users to select another page
|
27
32
|
print "Enter a page number > "
|
28
|
-
input = gets.chomp
|
29
|
-
|
33
|
+
input = gets.chomp
|
34
|
+
@url = pages[input.to_i-1] #use the users input to select the corresponding page URL from the #pages array
|
35
|
+
if @url
|
30
36
|
SteamUpcoming::Game.reset #clear out the class variable so it can be populated with a new list of games
|
31
37
|
make_games(@url) #create the games with the new chosen URL
|
32
38
|
list
|
@@ -36,18 +42,17 @@ class SteamUpcoming::CLI
|
|
36
42
|
end
|
37
43
|
|
38
44
|
def list_game(game) #list a game's details
|
39
|
-
|
40
|
-
game.add_game_attributes(attributes)
|
45
|
+
SteamUpcoming::Scraper.scrape_game_page(game.url)
|
41
46
|
puts "\n//-------------- #{game.name} --------------//\n".colorize(:yellow)
|
42
|
-
puts "About #{game.name}".colorize(:
|
47
|
+
puts "About #{game.name}".colorize(:yellow)
|
43
48
|
puts game.about
|
44
|
-
puts "\nTags:".colorize(:
|
49
|
+
puts "\nTags:".colorize(:yellow)
|
45
50
|
game.tags.each {|tag| puts " - #{tag}"}
|
46
|
-
puts "\nDetails:".colorize(:
|
51
|
+
puts "\nDetails:".colorize(:yellow)
|
47
52
|
game.details.each {|detail| puts " - #{detail}"}
|
48
|
-
puts "\nRelease Date:".colorize(:
|
53
|
+
puts "\nRelease Date:".colorize(:yellow)
|
49
54
|
puts " - #{game.release_date}"
|
50
|
-
puts "\nPlatforms:".colorize(:
|
55
|
+
puts "\nPlatforms:".colorize(:yellow)
|
51
56
|
game.platforms.each {|platform| puts " - #{platform}"}
|
52
57
|
puts ""
|
53
58
|
end
|
@@ -57,13 +62,14 @@ class SteamUpcoming::CLI
|
|
57
62
|
SteamUpcoming::Game.all.each.with_index do |game, index|
|
58
63
|
puts "#{index+1}. #{game.name}"
|
59
64
|
end
|
60
|
-
puts "\nPage #{current_page} of #{pages.count}".colorize(:
|
65
|
+
puts "\nPage #{current_page} of #{pages.count}".colorize(:white)
|
66
|
+
puts "\n#{number_of_results} results".colorize(:white)
|
61
67
|
end
|
62
68
|
|
63
69
|
def current_page
|
64
70
|
url = @url[-2,2] #return the last two characters of the URL string
|
65
71
|
array = url.split("").map {|x| x.to_i} #split the two characters into an array
|
66
|
-
array[0] == 0 ? current_page = array[0] + array[1] : current_page = "#{array[0]}".concat("#{array[1]}")
|
72
|
+
array[0] == 0 ? current_page = array[0] + array[1] : current_page = "#{array[0]}".concat("#{array[1]}").to_i
|
67
73
|
#if the first element is a letter (it converts to 0), add it to the second element
|
68
74
|
#if the both elements are numbers, concatenate them and return the new string
|
69
75
|
end
|
@@ -73,9 +79,9 @@ class SteamUpcoming::CLI
|
|
73
79
|
input = nil
|
74
80
|
while input != "exit" #loop user input until user types 'exit'
|
75
81
|
puts "\nLearn more about a game by typing a name or number.\n".colorize(:yellow)
|
76
|
-
puts "Enter \'list\'' to list games.".colorize(:
|
77
|
-
puts "Enter \'exit\' to exit.".colorize(:
|
78
|
-
puts "Enter \'page\' to switch pages.".colorize(:
|
82
|
+
puts "Enter \'list\'' to list games.".colorize(:yellow)
|
83
|
+
puts "Enter \'exit\' to exit.".colorize(:yellow)
|
84
|
+
puts "Enter \'page\' to switch pages.".colorize(:yellow)
|
79
85
|
print "\n > "
|
80
86
|
input = gets.chomp.strip
|
81
87
|
if input == "list"
|
data/lib/steam-upcoming/game.rb
CHANGED
@@ -1,36 +1,15 @@
|
|
1
|
-
# The SteamUpcoming::Game class is responsible for
|
2
|
-
#
|
1
|
+
# The SteamUpcoming::Game class is responsible for creating new Game objects with the information
|
2
|
+
# collected from the SteamUpcoming::Scraper class.
|
3
3
|
|
4
4
|
class SteamUpcoming::Game
|
5
5
|
attr_accessor :name, :release_date, :platforms, :url, :about, :tags, :details
|
6
6
|
|
7
7
|
@@all = []
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
game_hash.each {|key, value| self.send(("#{key}="), value)}
|
9
|
+
def initialize
|
11
10
|
@@all << self
|
12
11
|
end
|
13
12
|
|
14
|
-
def self.create_from_collection(games_hash_array) #create game objects from an array of hashes
|
15
|
-
games_hash_array.each do |game|
|
16
|
-
object = SteamUpcoming::Game.new(game)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def add_game_attributes(game_attributes_hash) #add attributes to the Game object
|
21
|
-
game_attributes_hash.each {|key, value| self.send(("#{key}="), value)}
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.create_pages(page_count) #Create the page urls
|
25
|
-
i = 1
|
26
|
-
pages = []
|
27
|
-
while i <= page_count.to_i
|
28
|
-
pages << "http://store.steampowered.com/search/?filter=comingsoon&sort_order=0&filter=comingsoon&page=#{i}"
|
29
|
-
i += 1
|
30
|
-
end
|
31
|
-
pages
|
32
|
-
end
|
33
|
-
|
34
13
|
private
|
35
14
|
def self.all #show all games
|
36
15
|
@@all
|
@@ -1,33 +1,26 @@
|
|
1
|
-
#The SteamUpcoming::Scraper class is responsible for scraping information off of the target webpage
|
2
|
-
#and
|
1
|
+
# The SteamUpcoming::Scraper class is responsible for scraping information off of the target webpage
|
2
|
+
# and creating the SteamUpcoming::Game objects in the process.
|
3
|
+
#
|
4
|
+
# When the program is first run, ::Scraper will only collect information from the index page. When a game
|
5
|
+
# is selected by the user, Scraper will then scrape the remaining attributes from the game page, add them
|
6
|
+
# to the selected ::Game object, and then output the information to the terminal.
|
3
7
|
|
4
8
|
class SteamUpcoming::Scraper
|
5
|
-
|
6
|
-
|
7
|
-
def self.scrape_index_page(index_url) #scrape the page and create an array of hashes (1 hash for each game)
|
9
|
+
def self.scrape_index_page(index_url) #scrape the page and create game objects with scraped properties
|
8
10
|
doc = Nokogiri::HTML(open(index_url))
|
9
|
-
game_array = []
|
10
11
|
doc.css(".search_result_row").each do |game|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
game_array << game_hash
|
12
|
+
game_object = SteamUpcoming::Game.new
|
13
|
+
game_object.name = game.css(".title").text
|
14
|
+
game_object.release_date = game.css(".search_released").text
|
15
|
+
game_object.platforms = gather_and_convert_platforms(game.css(".search_name p"))
|
16
|
+
game_object.url = game.first[1]
|
18
17
|
end
|
19
|
-
game_array
|
20
18
|
end
|
21
19
|
|
22
|
-
def self.
|
23
|
-
platforms = parent.children.map
|
24
|
-
|
25
|
-
|
26
|
-
platforms.select {|platform| platform != nil}
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.convert_platforms(platform_array) #convert the platform array items into actual names, because the source is an image, not text
|
30
|
-
platforms = platform_array.map! do |platform|
|
20
|
+
def self.gather_and_convert_platforms(parent) #gather platforms and convert the items into actual names, because the source is an image, not text
|
21
|
+
platforms = parent.children.map {|platform| platform.attr('class')}
|
22
|
+
platforms.delete_if {|platform| platform == nil}
|
23
|
+
platforms.map! do |platform|
|
31
24
|
if platform.include?("win")
|
32
25
|
platform = "Windows"
|
33
26
|
elsif platform.include?("mac")
|
@@ -40,27 +33,42 @@ class SteamUpcoming::Scraper
|
|
40
33
|
platform = "HTC Vive"
|
41
34
|
elsif platform.include?("oculusrift")
|
42
35
|
platform = "Oculus Rift"
|
43
|
-
else
|
44
|
-
|
36
|
+
else
|
37
|
+
next
|
45
38
|
end
|
46
39
|
end
|
47
|
-
platforms.select {|platform| platform != nil}
|
48
40
|
end
|
49
41
|
|
50
42
|
def self.scrape_game_page(game_url) #scrape the page and create a hash of game attributes
|
51
43
|
doc = Nokogiri::HTML(open(game_url))
|
52
|
-
about = doc.css(".
|
44
|
+
about = doc.css(".game_area_description")
|
53
45
|
tags = doc.css(".glance_tags a").map {|tag| tag.text}
|
54
46
|
details = doc.css(".game_area_details_specs")
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
SteamUpcoming::Game.all.each do |game|
|
48
|
+
if game_url == game.url
|
49
|
+
game.about = about.text.match(/\r|\n|\t/) ? about.text.delete("\t").delete("\r").delete("\n") : about.text
|
50
|
+
game.tags = tags.map {|tag| tag.match(/\r|\n|\t/) ? tag.delete("\t").delete("\r").delete("\n") : tag }
|
51
|
+
game.details = details.map {|child| child.text}
|
52
|
+
return game
|
53
|
+
end
|
54
|
+
end
|
60
55
|
end
|
61
56
|
|
62
|
-
def self.
|
57
|
+
def self.create_pages_with_urls(index_url) #scrape the pages to get the total number of pages
|
63
58
|
doc = Nokogiri::HTML(open(index_url))
|
64
59
|
page_count = doc.css(".search_pagination_right").first.children[5].text.to_i
|
60
|
+
i = 1
|
61
|
+
pages = []
|
62
|
+
while i <= page_count.to_i
|
63
|
+
pages << "http://store.steampowered.com/search/?filter=comingsoon&sort_order=0&filter=comingsoon&page=#{i}"
|
64
|
+
i += 1
|
65
|
+
end
|
66
|
+
pages
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.get_number_of_results(index_url)
|
70
|
+
doc = Nokogiri::HTML(open(index_url))
|
71
|
+
results = doc.css(".search_pagination_left").first.children.text
|
72
|
+
results.match(/\d{3,}/).to_s
|
65
73
|
end
|
66
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: steam-upcoming
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Cassara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|