diff options
Diffstat (limited to 'scrape.rb')
-rw-r--r-- | scrape.rb | 26 |
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' | |||
6 | require 'bundler/setup' | 6 | require 'bundler/setup' |
7 | Bundler.require :default | 7 | Bundler.require :default |
8 | 8 | ||
9 | MOON_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])) |
10 | db_existed = File.exists?(@config["database"]) | 24 | db_existed = File.exists?(@config["database"]) |
11 | db = Sequel.connect("sqlite://" + @config["database"]) | 25 | db = Sequel.connect("sqlite://" + @config["database"]) |
@@ -47,10 +61,6 @@ class Did < Sequel::Model | |||
47 | many_to_one :achievement | 61 | many_to_one :achievement |
48 | end | 62 | end |
49 | 63 | ||
50 | @moonimgs = Dir.entries(@config["moon_images"]).select do |img| | ||
51 | img.end_with? ".png" | ||
52 | end | ||
53 | |||
54 | def scrape_profile(profile, full) | 64 | def 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 |
168 | elsif ARGV[1] == "recolor" | 178 | elsif 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 |
175 | end | 185 | end |