about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--database.cpp4
-rw-r--r--database.h2
-rw-r--r--res/README.md (renamed from moons/README.md)0
-rw-r--r--res/blue.png (renamed from moons/blue.png)bin37618 -> 37618 bytes
-rw-r--r--res/brown.png (renamed from moons/brown.png)bin38150 -> 38150 bytes
-rw-r--r--res/cyan.png (renamed from moons/cyan.png)bin33139 -> 33139 bytes
-rw-r--r--res/green.png (renamed from moons/green.png)bin36760 -> 36760 bytes
-rw-r--r--res/orange.png (renamed from moons/orange.png)bin36465 -> 36465 bytes
-rw-r--r--res/pink.png (renamed from moons/pink.png)bin30838 -> 30838 bytes
-rw-r--r--res/purple.png (renamed from moons/purple.png)bin32331 -> 32331 bytes
-rw-r--r--res/red.png (renamed from moons/red.png)bin37165 -> 37165 bytes
-rw-r--r--res/star.png (renamed from moons/star.png)bin27829 -> 27829 bytes
-rw-r--r--res/white.png (renamed from moons/white.png)bin29878 -> 29878 bytes
-rw-r--r--res/yellow.png (renamed from moons/yellow.png)bin32939 -> 32939 bytes
-rw-r--r--schema.sql2
-rw-r--r--scrape.rb26
16 files changed, 22 insertions, 12 deletions
diff --git a/database.cpp b/database.cpp index f8b5016..2885d1f 100644 --- a/database.cpp +++ b/database.cpp
@@ -44,7 +44,7 @@ database::~database()
44 44
45achievement database::getRandomAchievement() const 45achievement database::getRandomAchievement() const
46{ 46{
47 std::string queryString = "SELECT achievements.achievement_id, achievements.game_id, achievements.title, games.moon_image FROM achievements INNER JOIN games ON games.game_id = achievements.game_id ORDER BY RANDOM() LIMIT 1"; 47 std::string queryString = "SELECT achievements.achievement_id, achievements.game_id, achievements.title, games.color FROM achievements INNER JOIN games ON games.game_id = achievements.game_id ORDER BY RANDOM() LIMIT 1";
48 48
49 sqlite3_stmt* ppstmt; 49 sqlite3_stmt* ppstmt;
50 if (sqlite3_prepare_v2( 50 if (sqlite3_prepare_v2(
@@ -73,7 +73,7 @@ achievement database::getRandomAchievement() const
73 result.achievementId = sqlite3_column_int(ppstmt, 0); 73 result.achievementId = sqlite3_column_int(ppstmt, 0);
74 result.gameId = sqlite3_column_int(ppstmt, 1); 74 result.gameId = sqlite3_column_int(ppstmt, 1);
75 result.title = reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 2)); 75 result.title = reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 2));
76 result.moonImage = reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 3)); 76 result.color = reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 3));
77 77
78 sqlite3_finalize(ppstmt); 78 sqlite3_finalize(ppstmt);
79 79
diff --git a/database.h b/database.h index 560eeda..a616318 100644 --- a/database.h +++ b/database.h
@@ -9,7 +9,7 @@ struct achievement {
9 int achievementId; 9 int achievementId;
10 int gameId; 10 int gameId;
11 std::string title; 11 std::string title;
12 std::string moonImage; 12 std::string color;
13}; 13};
14 14
15class database { 15class database {
diff --git a/moons/README.md b/res/README.md index 876f0db..876f0db 100644 --- a/moons/README.md +++ b/res/README.md
diff --git a/moons/blue.png b/res/blue.png index 5e4ca02..5e4ca02 100644 --- a/moons/blue.png +++ b/res/blue.png
Binary files differ
diff --git a/moons/brown.png b/res/brown.png index 6a31b16..6a31b16 100644 --- a/moons/brown.png +++ b/res/brown.png
Binary files differ
diff --git a/moons/cyan.png b/res/cyan.png index 8984126..8984126 100644 --- a/moons/cyan.png +++ b/res/cyan.png
Binary files differ
diff --git a/moons/green.png b/res/green.png index 5e7d311..5e7d311 100644 --- a/moons/green.png +++ b/res/green.png
Binary files differ
diff --git a/moons/orange.png b/res/orange.png index 06ca595..06ca595 100644 --- a/moons/orange.png +++ b/res/orange.png
Binary files differ
diff --git a/moons/pink.png b/res/pink.png index 3b1521b..3b1521b 100644 --- a/moons/pink.png +++ b/res/pink.png
Binary files differ
diff --git a/moons/purple.png b/res/purple.png index 9eeacf9..9eeacf9 100644 --- a/moons/purple.png +++ b/res/purple.png
Binary files differ
diff --git a/moons/red.png b/res/red.png index 2c0ef77..2c0ef77 100644 --- a/moons/red.png +++ b/res/red.png
Binary files differ
diff --git a/moons/star.png b/res/star.png index 29263d5..29263d5 100644 --- a/moons/star.png +++ b/res/star.png
Binary files differ
diff --git a/moons/white.png b/res/white.png index fae666b..fae666b 100644 --- a/moons/white.png +++ b/res/white.png
Binary files differ
diff --git a/moons/yellow.png b/res/yellow.png index 8c012df..8c012df 100644 --- a/moons/yellow.png +++ b/res/yellow.png
Binary files differ
diff --git a/schema.sql b/schema.sql index 61fdc45..ade7522 100644 --- a/schema.sql +++ b/schema.sql
@@ -8,7 +8,7 @@ CREATE UNIQUE INDEX `profile_by_path` ON `profiles`(`profile_path`);
8CREATE TABLE `games` ( 8CREATE TABLE `games` (
9 `game_id` INTEGER PRIMARY KEY, 9 `game_id` INTEGER PRIMARY KEY,
10 `steam_appid` INTEGER NOT NULL, 10 `steam_appid` INTEGER NOT NULL,
11 `moon_image` VARCHAR(255) NOT NULL 11 `color` VARCHAR(255) NOT NULL
12); 12);
13 13
14CREATE UNIQUE INDEX `game_by_appid` ON `games`(`steam_appid`); 14CREATE UNIQUE INDEX `game_by_appid` ON `games`(`steam_appid`);
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