about summary refs log tree commit diff stats
path: root/scrape.rb
diff options
context:
space:
mode:
Diffstat (limited to 'scrape.rb')
-rw-r--r--scrape.rb26
1 files changed, 18 insertions, 8 deletions
diff --git a/scrape.rb b/scrape.rb index 6f3a8e4..dfeb356 100644 --- a/scrape.rb +++ b/scrape.rb
@@ -6,6 +6,20 @@ require 'rubygems'
6require 'bundler/setup' 6require 'bundler/setup'
7Bundler.require :default 7Bundler.require :default
8 8
9MOON_COLORS = [
10 :blue,
11 :brown,
12 :cyan,
13 :green,
14 :orange,
15 :pink,
16 :purple,
17 :red,
18 :star,
19 :white,
20 :yellow
21]
22
9@config = YAML.load(open(ARGV[0])) 23@config = YAML.load(open(ARGV[0]))
10db_existed = File.exists?(@config["database"]) 24db_existed = File.exists?(@config["database"])
11db = Sequel.connect("sqlite://" + @config["database"]) 25db = Sequel.connect("sqlite://" + @config["database"])
@@ -47,10 +61,6 @@ class Did < Sequel::Model
47 many_to_one :achievement 61 many_to_one :achievement
48end 62end
49 63
50@moonimgs = Dir.entries(@config["moon_images"]).select do |img|
51 img.end_with? ".png"
52end
53
54def scrape_profile(profile, full) 64def scrape_profile(profile, full)
55 if full 65 if full
56 url = "https://steamcommunity.com/#{profile.profile_path}/games/?tab=all" 66 url = "https://steamcommunity.com/#{profile.profile_path}/games/?tab=all"
@@ -76,9 +86,9 @@ def scrape_profile(profile, full)
76 if Game.where(steam_appid: id).count > 0 86 if Game.where(steam_appid: id).count > 0
77 game = Game.where(steam_appid: id).first 87 game = Game.where(steam_appid: id).first
78 else 88 else
79 moon_index = Random.rand(@moonimgs.size) 89 moon_index = Random.rand(MOON_COLORS.size)
80 90
81 game = Game.new(steam_appid: id, moon_image: @moonimgs[moon_index]) 91 game = Game.new(steam_appid: id, color: MOON_COLORS[moon_index])
82 game.save 92 game.save
83 93
84 storepage = Nokogiri::HTML( 94 storepage = Nokogiri::HTML(
@@ -167,9 +177,9 @@ elsif ARGV[1] == "full"
167 end 177 end
168elsif ARGV[1] == "recolor" 178elsif ARGV[1] == "recolor"
169 Game.all.each do |game| 179 Game.all.each do |game|
170 moon_index = Random.rand(@moonimgs.size) 180 moon_index = Random.rand(MOON_COLORS.size)
171 181
172 game.moon_image = @moonimgs[moon_index] 182 game.color = MOON_COLORS[moon_index]
173 game.save 183 game.save
174 end 184 end
175end 185end