gogdb 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82cfcbddbebad876b49fd5dd07b98524daefdce5
4
- data.tar.gz: 1e1c39defc8346d307931e31dd453bff05011171
3
+ metadata.gz: db7cfdc7fc7c0b4badbf49971fc198d5b53790ec
4
+ data.tar.gz: 835af1c3fd059c28e0a198d367d429febacc29ac
5
5
  SHA512:
6
- metadata.gz: aad7dc8e62fe1867dfeda1d8505c0dc5156e88defa212916e2ff664bc2dc2461af0ad00a01793e6c5d0a67af04bbc98b0ac907a78ce3407a7d9cd2b71d13f57a
7
- data.tar.gz: c3d4d03217dd48daee67bcd48eb52f435c8adcaccfe2c44a3b9910006be50300f24c0b7c83661af8d22a57a48bb064fadd6595a4299ac6d6a0a949664ba6934d
6
+ metadata.gz: 41e49bd2545e506a683298d0f99df8a39ed9f6d0ca3ccc8f5b79ad15e1d09f751fd8cbba7ee93a9cfd51d937905fc0ed40464ace97ce33c85cbc8d8728996678
7
+ data.tar.gz: c237f2b58cf828d181e89e138edfdfdb8bfb3d4f2745f1623001e310cc8acca456af8b7f9db7ac10872a8ea151af3a3024c1d9f6fb8ed97edea0e39947b604a6
@@ -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;
@@ -3,6 +3,8 @@ require 'colorize'
3
3
  require 'net/http'
4
4
  require 'net/ping'
5
5
  require 'json'
6
+ require 'yaml'
7
+
6
8
  require 'gogdb/version'
7
9
  require 'gogdb/engine'
8
10
  require 'gogdb/utils'
@@ -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 "-L" => :list
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 "sync [options]", "Syncs all data between databases"
13
- def sync
14
- end
15
-
16
- desc "fetch [options]", "Fetches items from gog.com and updates database"
17
- method_option :limit, :type => :numeric, :desc => "How many items to fetch [0 - no limit]", :default => 0
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
@@ -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
- url = GOG_GAMES_URL if options[:type] == "games"
14
- url = GOG_MOVIES_URL if options[:type] == "movies"
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
- pages_number = get_pages_number(url)
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
- # Loop through pages
21
- count = 0;
22
- catch :limitReached do
23
- for i in 0..pages_number do
24
- # Let's get products number and URL's for current page
25
- items_data = get_data(url)['products']
26
- items_number = items_data.length
27
-
28
- # Loop through products and get data of every one
29
- for i in 0..items_number do
30
- item_url = items_data[i]['url']
31
- item_data = get_data("#{GOG_URL}#{item_url}")['gameProductData']
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
- @logger.debug "Item received: #{item_data['title']}"
40
+ @logger.debug "Item received: #{item_data['title']}"
34
41
 
35
- count += 1
36
- # Break loop if limit is reached
37
- throw :limitReached if count >= options[:limit] && options[:limit] != 0
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
@@ -1,3 +1,3 @@
1
1
  module Gogdb
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-01-03 00:00:00.000000000 Z
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