steam-upcoming 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e0b73c4b1a02bbca55e3d395ce27870817e386b
4
+ data.tar.gz: f16aa465b2d3db2867c9878518f91fac83fe2f05
5
+ SHA512:
6
+ metadata.gz: 721c3d8bc6d9163d0dcb3a2d36168eeb4bd1bdc46cf8d93cba437b9080907aa97af5d70f927192125f346760b2fe6a80c1cc6a490d091643fe2c4650bb2a102f
7
+ data.tar.gz: 6db0be667baa2d2e0a3aaf3065fff1c859a8c5ac7ec6fba397803cb3414d380b71cd79da0da0497fdc9d0dd3f15c9e92253b168a839d7a5470abff161e3a590b
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/steam-upcoming'
4
+
5
+ SteamUpcoming::CLI.new.run
@@ -0,0 +1,7 @@
1
+ require 'open-uri'
2
+ require 'pry'
3
+ require 'nokogiri'
4
+ require "colorize"
5
+ require_relative "../lib/steam-upcoming/cli.rb"
6
+ require_relative "../lib/steam-upcoming/game.rb"
7
+ require_relative "../lib/steam-upcoming/scraper.rb"
@@ -0,0 +1,5 @@
1
+ require_relative "../config/environment"
2
+
3
+ module SteamUpcoming
4
+ end
5
+
@@ -0,0 +1,102 @@
1
+ class SteamUpcoming::CLI
2
+ attr_accessor :url
3
+
4
+ BASE_URL = "http://store.steampowered.com/search/?filter=comingsoon&sort_order=0&filter=comingsoon&page=1"
5
+
6
+
7
+ def initialize
8
+ @url = "http://store.steampowered.com/search/?filter=comingsoon&sort_order=0&filter=comingsoon&page=1"
9
+ end
10
+
11
+ def run #run the program
12
+ puts "\nFetching latest games from the Steam Network...".colorize(:yellow)
13
+ make_games(BASE_URL)
14
+ pages
15
+ start
16
+ end
17
+
18
+ def make_games(url) #creates the list of games from the URL
19
+ game_array = SteamUpcoming::Scraper.scrape_index_page(url)
20
+ SteamUpcoming::Game.create_from_collection(game_array)
21
+ end
22
+
23
+ def pages #generate list of pages
24
+ pages = SteamUpcoming::Game.create_pages(SteamUpcoming::Scraper.page_count(BASE_URL))
25
+ end
26
+
27
+ def change_page #allow the users to select another page
28
+ print "Enter a page number > "
29
+ input = gets.chomp.strip
30
+ if @url = pages[input.to_i-1]
31
+ SteamUpcoming::Game.reset
32
+ make_games(@url)
33
+ list
34
+ else
35
+ puts "#{input}".concat(" is not a valid page number. Please enter a number between 1 and #{pages.count}.").colorize(:red)
36
+ end
37
+ end
38
+
39
+ def list_game(game) #list a game's details
40
+ attributes = SteamUpcoming::Scraper.scrape_game_page(game.url)
41
+ game.add_game_attributes(attributes)
42
+ puts "\n//-------------- #{game.name} --------------//\n".colorize(:yellow)
43
+ puts "About #{game.name}".colorize(:light_blue)
44
+ puts game.about
45
+ puts "\nTags:".colorize(:light_blue)
46
+ game.tags.each {|tag| puts " - #{tag}"}
47
+ puts "\nDetails:".colorize(:light_blue)
48
+ game.details.each {|detail| puts " - #{detail}"}
49
+ puts "\nRelease Date:".colorize(:light_blue)
50
+ puts " - #{game.release_date}"
51
+ puts "\nPlatforms:".colorize(:light_blue)
52
+ game.platforms.each {|platform| puts " - #{platform}"}
53
+ puts ""
54
+ end
55
+
56
+ def list #list the games
57
+ puts "\n//-------------- Upcoming Games on Steam --------------//\n".colorize(:yellow)
58
+ SteamUpcoming::Game.all.each.with_index do |game, index|
59
+ puts "#{index+1}. #{game.name}"
60
+ end
61
+ puts "\nPage #{current_page} of #{pages.count}".colorize(:yellow)
62
+ end
63
+
64
+ def current_page
65
+ url = @url[-2,2]
66
+ array = url.split("").map {|x| x.to_i}
67
+ array[0] == 0 ? current_page = array[0] + array[1] : current_page = "#{array[0]}".concat("#{array[1]}")
68
+ end
69
+
70
+ def start #start the program loop
71
+ list
72
+ input = nil
73
+ while input != "exit"
74
+ puts "\nLearn more about a game by typing a name or number.\n".colorize(:yellow)
75
+ puts "Enter \'list\'' to list games.".colorize(:light_blue)
76
+ puts "Enter \'exit\' to exit.".colorize(:light_blue)
77
+ puts "Enter \'page\' to switch pages.".colorize(:light_blue)
78
+ print "\n > "
79
+ input = gets.chomp.strip
80
+ if input == "list"
81
+ list
82
+ elsif input.to_i == 0 #if input is a name
83
+ if game = SteamUpcoming::Game.find_by_name(input)
84
+ list_game(game)
85
+ elsif input == "exit"
86
+ break
87
+ elsif input == "page"
88
+ change_page
89
+ else
90
+ puts "\'#{input}\'".concat(" is not a valid title.").colorize(:red)
91
+ end
92
+ elsif input.to_i > 0 #if a number, look up the number
93
+ if game = SteamUpcoming::Game.find(input.to_i)
94
+ list_game(game)
95
+ else
96
+ puts "\'#{input}\'".concat(" is not a valid number. Please enter a number between 1 and #{SteamUpcoming::Game.all.count}.").colorize(:red)
97
+ end
98
+ end
99
+ end
100
+ puts "\nShutting down...\n".colorize(:red)
101
+ end
102
+ end
@@ -0,0 +1,49 @@
1
+ class SteamUpcoming::Game
2
+ attr_accessor :name, :release_date, :platforms, :url, :about, :tags, :details
3
+
4
+ @@all = []
5
+
6
+ def initialize(game_hash)
7
+ game_hash.each {|key, value| self.send(("#{key}="), value)}
8
+ @@all << self
9
+ end
10
+
11
+ def self.create_from_collection(games_hash_array) #create game objects from an array of hashes
12
+ games_hash_array.each do |game|
13
+ object = SteamUpcoming::Game.new(game)
14
+ end
15
+ end
16
+
17
+ def add_game_attributes(game_attributes_hash) #add attributes to game
18
+ game_attributes_hash.each {|key, value| self.send(("#{key}="), value)}
19
+ end
20
+
21
+ def self.create_pages(page_count) #create the page urls
22
+ i = 1
23
+ pages = []
24
+ while i <= page_count.to_i
25
+ pages << "http://store.steampowered.com/search/?filter=comingsoon&sort_order=0&filter=comingsoon&page=#{i}"
26
+ i += 1
27
+ end
28
+ pages
29
+ end
30
+
31
+ def self.all #show all games
32
+ @@all
33
+ end
34
+
35
+ def self.reset #clear the list of games
36
+ @@all.clear
37
+ end
38
+
39
+ def self.find(id) #find a game based on number
40
+ self.all[id-1]
41
+ end
42
+
43
+ def self.find_by_name(name) #find a game based on name
44
+ self.all.detect do |game|
45
+ game.name.downcase == name
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,66 @@
1
+ #The SteamUpcoming::Scraper class is responsible for scraping information off of the target webpage
2
+ #and outputting hashes of information to be used by the SteamUpcoming::Game class.
3
+
4
+ class SteamUpcoming::Scraper
5
+ attr_accessor :name, :release_date, :platforms, :url
6
+
7
+ def self.scrape_index_page(index_url) #scrape the page and create an array of hashes (1 hash for each game)
8
+ doc = Nokogiri::HTML(open(index_url))
9
+ game_array = []
10
+ doc.css(".search_result_row").each do |game|
11
+ game_hash = {
12
+ :name=> game.css(".title").text,
13
+ :release_date=> game.css(".search_released").text,
14
+ :platforms=> self.convert_platforms(gather_platforms(game.css(".search_name p"))),
15
+ :url=> game.first[1]
16
+ }
17
+ game_array << game_hash
18
+ end
19
+ game_array
20
+ end
21
+
22
+ def self.gather_platforms(parent) #gather a list of platforms, then return an array of legit platforms
23
+ platforms = parent.children.map do |platform|
24
+ platform.attr('class')
25
+ end
26
+ platforms.select {|platform| platform != nil}
27
+ end
28
+
29
+ def self.convert_platforms(platform_array) #need to convert the platform array items into actual names, because the source is an image, not
30
+ platforms = platform_array.map! do |platform|
31
+ if platform.include?("win")
32
+ platform = "Windows"
33
+ elsif platform.include?("mac")
34
+ platform = "Mac"
35
+ elsif platform.include?("linux")
36
+ platform = "Linux"
37
+ elsif platform.include?("steamplay")
38
+ platform = "Steam Play"
39
+ elsif platform.include?("htcvive")
40
+ platform = "HTC Vive"
41
+ elsif platform.include?("oculusrift")
42
+ platform = "Oculus Rift"
43
+ else
44
+ platform = nil
45
+ end
46
+ end
47
+ platforms.select {|platform| platform != nil}
48
+ end
49
+
50
+ def self.scrape_game_page(game_url)
51
+ doc = Nokogiri::HTML(open(game_url))
52
+ about = doc.css(".game_description_snippet")
53
+ tags = doc.css(".glance_tags a").map {|tag| tag.text}
54
+ details = doc.css(".game_area_details_specs")
55
+ game_attributes_hash = {
56
+ :about => about.text.match(/\r|\n|\t/) ? about.text.delete("\t").delete("\r").delete("\n") : about.text,
57
+ :tags => tags.map {|tag| tag.match(/\r|\n|\t/) ? tag.delete("\t").delete("\r").delete("\n") : tag },
58
+ :details => details.map {|child| child.text}
59
+ }
60
+ end
61
+
62
+ def self.page_count(index_url)
63
+ doc = Nokogiri::HTML(open(index_url))
64
+ page_count = doc.css(".search_pagination_right").first.children[5].text.to_i
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steam-upcoming
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Cassara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - cassaram09@gmail.com
100
+ executables:
101
+ - steam-upcoming
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - bin/steam-upcoming
106
+ - config/environment.rb
107
+ - lib/steam-upcoming.rb
108
+ - lib/steam-upcoming/cli.rb
109
+ - lib/steam-upcoming/game.rb
110
+ - lib/steam-upcoming/scraper.rb
111
+ homepage: http://rubygems.org/gems/steam-upcoming
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.6.4
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: This gem collects a list of upcoming games from the Steam Network via scraping.
135
+ test_files: []