gogdb 0.0.1 → 0.0.2
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 +4 -4
- data/CHANGELOG.md +18 -0
- data/lib/gogdb.rb +2 -0
- data/lib/gogdb/cli.rb +44 -10
- data/lib/gogdb/engine.rb +31 -21
- data/lib/gogdb/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db7cfdc7fc7c0b4badbf49971fc198d5b53790ec
|
4
|
+
data.tar.gz: 835af1c3fd059c28e0a198d367d429febacc29ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41e49bd2545e506a683298d0f99df8a39ed9f6d0ca3ccc8f5b79ad15e1d09f751fd8cbba7ee93a9cfd51d937905fc0ed40464ace97ce33c85cbc8d8728996678
|
7
|
+
data.tar.gz: c237f2b58cf828d181e89e138edfdfdb8bfb3d4f2745f1623001e310cc8acca456af8b7f9db7ac10872a8ea151af3a3024c1d9f6fb8ed97edea0e39947b604a6
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
## 0.0.21 (currently in development)
|
2
|
+
|
3
|
+
nil
|
4
|
+
|
5
|
+
## 0.0.2
|
6
|
+
|
7
|
+
Features:
|
8
|
+
|
9
|
+
* Setup command, which creates config file
|
10
|
+
* Implemented config check before every command
|
11
|
+
* Added `gogdb version` alias `gogdb --version`
|
12
|
+
* Added request limit option to `gogdb fetch`
|
13
|
+
* Added default database path to config
|
14
|
+
* Fixed `--type` parameter (you could fetch only games or movies, but not both)
|
15
|
+
|
16
|
+
## 0.0.1
|
17
|
+
|
18
|
+
Initial release;
|
data/lib/gogdb.rb
CHANGED
data/lib/gogdb/cli.rb
CHANGED
@@ -1,27 +1,61 @@
|
|
1
1
|
module Gogdb
|
2
2
|
|
3
3
|
class Cli < Thor
|
4
|
+
def initialize(*args)
|
5
|
+
check_config
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
4
9
|
package_name "Gogdb"
|
5
|
-
map "
|
10
|
+
map "--version" => :version
|
6
11
|
|
7
12
|
desc "version", "Shows current version"
|
8
13
|
def version
|
9
14
|
puts Gogdb::VERSION
|
10
15
|
end
|
11
16
|
|
12
|
-
desc "
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
method_option :
|
18
|
-
method_option :type, :type => :string, :enum => ["all", "games", "movies"], :desc => "Type items to fetch", :default => "all"
|
19
|
-
method_option :debug, :type => :boolean, :desc => "Show debug messages", :default => false
|
20
|
-
method_option :silent, :type => :boolean, :desc => "Hide all output", :default => false
|
17
|
+
desc "fetch [options]", "Fetches data and updates database"
|
18
|
+
method_option :limit, :type => :numeric, :desc => "How many items you want to fetch. 0 means no limit.", :default => 0
|
19
|
+
method_option :requestLimit, :type => :numeric, :desc => "Limit requests per minute. 0 means no limit.", :default => 12
|
20
|
+
method_option :type, :type => :string, :enum => ["all", "games", "movies"], :desc => "What type of items you want to fetch.", :default => "all"
|
21
|
+
method_option :debug, :type => :boolean, :desc => "Enables debug messages. Useful if you want to see what's happening step-by-step.", :default => false
|
22
|
+
method_option :silent, :type => :boolean, :desc => "Hides all output. Even debug messages.", :default => false
|
21
23
|
def fetch
|
22
24
|
@e = Gogdb::Engine.new(options)
|
23
25
|
@e.fetch(options)
|
24
26
|
end
|
25
27
|
|
28
|
+
desc "setup", "Run automatic configuration."
|
29
|
+
def setup
|
30
|
+
db_path = ask("Enter path you want to save database (default #{ENV['HOME']}/.gogdb):")
|
31
|
+
|
32
|
+
db_path = "#{ENV['HOME']}/.gogdb" if db_path.empty?
|
33
|
+
|
34
|
+
@config = {
|
35
|
+
"path" => db_path
|
36
|
+
}
|
37
|
+
|
38
|
+
# Stop execution if user does not want to overwrite.
|
39
|
+
if File.exist?("config.yml")
|
40
|
+
exit unless yes? "Config file already exists. Overwrite?(y/n)", :red
|
41
|
+
end
|
42
|
+
|
43
|
+
File.open("config.yml", "w") { |file|
|
44
|
+
file.write(@config.to_yaml)
|
45
|
+
}
|
46
|
+
|
47
|
+
say "Config written successfully.", :green
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Checks if config file exists. If not, runs setup automatically.
|
53
|
+
def check_config
|
54
|
+
unless File.exist?("config.yml")
|
55
|
+
say "It appears that you don't have config in place. You need to enter following details to make Gogdb work;", :yellow
|
56
|
+
setup
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
26
60
|
end
|
27
61
|
end
|
data/lib/gogdb/engine.rb
CHANGED
@@ -10,31 +10,41 @@ module Gogdb
|
|
10
10
|
#
|
11
11
|
# @param [Hash] options Additional options such as :limit and :type
|
12
12
|
def fetch(options)
|
13
|
-
|
14
|
-
|
13
|
+
# If user passed type parameter, we need to figure it out which urls we
|
14
|
+
# need actually to fetch
|
15
|
+
sources = []
|
16
|
+
sources.push(GOG_GAMES_URL) if options[:type] == "games"
|
17
|
+
sources.push(GOG_MOVIES_URL) if options[:type] == "movies"
|
18
|
+
sources = [GOG_GAMES_URL, GOG_MOVIES_URL] if options[:type] == "all" || options[:type] == nil
|
15
19
|
|
16
|
-
|
17
|
-
@logger.debug "Pages received: #{pages_number}"
|
18
|
-
nil if pages_number < 1 # Do nothing if there are no pages
|
20
|
+
sleep_time = 60 / options[:requestLimit]
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
sources.each do |source|
|
23
|
+
pages_number = get_pages_number(source)
|
24
|
+
@logger.debug "Pages received: #{pages_number}"
|
25
|
+
nil if pages_number < 1 # Do nothing if there are no pages
|
26
|
+
|
27
|
+
# Loop through pages
|
28
|
+
count = 0;
|
29
|
+
catch :limitReached do
|
30
|
+
for i in 0..pages_number do
|
31
|
+
# Let's get products number and URL's for current page
|
32
|
+
items_data = get_data(source)['products']
|
33
|
+
items_number = items_data.length
|
34
|
+
|
35
|
+
# Loop through products and get data of every one
|
36
|
+
for i in 0..items_number do
|
37
|
+
item_url = items_data[i]['url']
|
38
|
+
item_data = get_data("#{GOG_URL}#{item_url}")['gameProductData']
|
32
39
|
|
33
|
-
|
40
|
+
@logger.debug "Item received: #{item_data['title']}"
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
42
|
+
count += 1
|
43
|
+
# Break loop if limit is reached
|
44
|
+
throw :limitReached if count >= options[:limit] && options[:limit] != 0
|
45
|
+
|
46
|
+
sleep(sleep_time)
|
47
|
+
end
|
38
48
|
end
|
39
49
|
end
|
40
50
|
end
|
data/lib/gogdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gogdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rolandas Barysas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,6 +130,7 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- CHANGELOG.md
|
133
134
|
- LICENSE
|
134
135
|
- README.md
|
135
136
|
- bin/gogdb
|