magento_remote 0.2.1 → 0.2.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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDdiMDk3MTBjMjA1Y2MwZmEwMGI5OWY1ZTE5YmMwMDg2OTU3MWJjMw==
5
- data.tar.gz: !binary |-
6
- NTg5NTg2ZDNiZGE1OGE3OGUzNDgwYjFlMDdlNjMyZjYxOTg5NmY0Mg==
2
+ SHA1:
3
+ metadata.gz: a78e92d36ef4418b06d0729137865dc0effeee95
4
+ data.tar.gz: 7e245671e51c0edef338cbb6c9137fc46414a919
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZDNmZTkwODcyZWY3NDFiODcyMzA1YmZmOGI5NzhkZGM0NDAwYjdhZWY0MzJi
10
- NWY3NTlhNGUxMmI0ODk2Yzk3N2Y4OTgyMGQ0ZDc0NzU3NTAzNzQ4N2Y5ZDg1
11
- MjNiOWIwZGFiNWM0YmQzMWFkYzFhMzcyZTg4ZTNhMTlkYjA2ZWM=
12
- data.tar.gz: !binary |-
13
- OWY3NGI4OWU0NDM4YWVkNWY5MWZkOWU3MzM2OTdlMjI2ZmFkNTZlYjg5MjA3
14
- OGE0MTY1MDFhN2E1M2FiMTBjMDA4MTY2NzRiMGEzNmJjMjA4MmM3NGNhMGM5
15
- Y2YzNmJmNWYzZmQ5NzVjMjc2ZWMyMDc5NjcyMjFhNWYwOTU5ODk=
6
+ metadata.gz: 55d1b8980413626b557c1b39d1749e4d5facf5fa1eff0a3985b6cf271239e3d473b11a376fc5fbc356a6d66f253315e2f4fe061244e39bb84d75744900883a10
7
+ data.tar.gz: 47127fd9fabdc228e065b5c8bc997c2c4081eb1b0b3ff7213ee5f4acca995cc7ba42732a2766664a532ef23aba09b02662e02acd445c0e3a752af49fb603c56e
@@ -58,7 +58,7 @@ optparse = OptionParser.new do |opts|
58
58
  opts.separator "General options"
59
59
 
60
60
  opts.on_tail('--version', 'Show version.') do
61
- puts "magento_add_to_cart #{MagentoRemote::VERSION}"
61
+ puts "#{program_name} #{MagentoRemote::VERSION}"
62
62
  exit 0
63
63
  end
64
64
  opts.on('-h', '--help', 'Show help.') do
data/bin/magento_scrape CHANGED
@@ -18,6 +18,9 @@ optparse = OptionParser.new do |opts|
18
18
  opts.on('-b', '--base-uri URI', 'base URI of shop.') do |b|
19
19
  options[:base_uri] = b
20
20
  end
21
+ opts.on('-w', '--wait SECONDS', Float, 'SECONDS to wait after each request (default: 0)') do |b|
22
+ options[:sleep_time] = b
23
+ end
21
24
 
22
25
  opts.separator ""
23
26
  opts.separator "Product options"
@@ -71,8 +74,9 @@ end
71
74
  return_code = 0
72
75
 
73
76
  options[:start_pid] ||= 0
77
+ options[:sleep_time] ||= 0
74
78
 
75
- matches = mech.scrape_products options[:start_pid].to_i, options[:limit].to_i
79
+ matches = mech.scrape_products(options[:start_pid].to_i, options[:limit].to_i, options[:sleep_time])
76
80
  if matches.nil?
77
81
  puts "Nothing found"
78
82
  else
@@ -154,15 +154,28 @@ class MagentoMech
154
154
  # Arguments
155
155
  # limit: Maximum number of product_ids to check
156
156
  # start_pid: With which product id to start scraping
157
+ # sleep_time: Time to sleep after each try
157
158
  # returns [[name1, product_id1, instock?1],[name2, p_id2...]...]
158
159
  # or nil if not found.
159
160
  # yielding would be nice
160
- def scrape_products start_pid, limit
161
+ def scrape_products start_pid, limit, sleep_time=0
161
162
  products = []
162
163
  limit.times do |idx|
163
164
  url = relative_url("/catalog/product/view/id/#{start_pid + idx + 1}")
164
- @mech.get url rescue next
165
- #if @mech.response_code
165
+ begin
166
+ @mech.get url
167
+ rescue
168
+ # This is probably a 404
169
+ sleep sleep_time
170
+ next
171
+ end
172
+
173
+ if @mech.page.code == '429'
174
+ # Too many requests! Sleep and try again,
175
+ sleep 2
176
+ @mech.get url # rescue raise
177
+ end
178
+
166
179
  product_name = @mech.page.search('.product-name .roundall')[0].text
167
180
  wishlist_link = @mech.page.search(".link-wishlist")[0]
168
181
  wishlist_link.attributes['href'].value[/product\/(\d+)/]
@@ -171,6 +184,7 @@ class MagentoMech
171
184
  if block_given?
172
185
  yield [product_name, pid]
173
186
  end
187
+ sleep sleep_time
174
188
  end
175
189
 
176
190
  return products
@@ -1,3 +1,3 @@
1
1
  module MagentoRemote
2
- VERSION = "0.2.1".freeze
2
+ VERSION = "0.2.2".freeze
3
3
  end
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magento_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Wolfsteller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-08 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: terminal-table
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.6'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: inifile
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Allows ordering through a (defaultish) magento web page.
@@ -106,10 +106,10 @@ executables:
106
106
  extensions: []
107
107
  extra_rdoc_files: []
108
108
  files:
109
- - .gitignore
110
- - .rspec
111
- - .ruby-gemset
112
- - .ruby-version
109
+ - ".gitignore"
110
+ - ".rspec"
111
+ - ".ruby-gemset"
112
+ - ".ruby-version"
113
113
  - Gemfile
114
114
  - LICENSE.txt
115
115
  - README.md
@@ -135,17 +135,17 @@ require_paths:
135
135
  - lib
136
136
  required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ! '>='
138
+ - - ">="
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ! '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.2.2
148
+ rubygems_version: 2.5.1
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Login to a magento shop and do stuff.