amazon_order 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/README.md +18 -7
- data/amazon_order.gemspec +1 -1
- data/lib/amazon_order/client.rb +18 -3
- data/lib/amazon_order/version.rb +1 -1
- data/lib/amazon_order/writer.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52166bb75c3fe54c69163a6878e2b8a34a3d8590
|
4
|
+
data.tar.gz: 35af75fbdcbec9a9de5bdf380b45bb97dcb513ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e75e7d9b750bb9bdb970758c100271bc4910d9551ac273d7b8c267505607ac0187189e3f1db67d356464d6ed7c031dfb0b509260993352caa4481e4d5dfc849
|
7
|
+
data.tar.gz: 9ba44f92e89e6e60a44da9a080f44f3d95601c22e3fc57d6c211d0b0fd0eee2766a5a90254e49c89866b51f936f103a0feb0178ac48607bc2c0801a9d5ebf0a1
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -37,11 +37,14 @@ Or install it yourself as:
|
|
37
37
|
|
38
38
|
[chromedriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) is required. Please [download chromedriver](http://chromedriver.storage.googleapis.com/index.html) and update chromedriver regularly.
|
39
39
|
|
40
|
-
Create
|
40
|
+
Create credentials following the instructions of https://github.com/kyamaguchi/amazon_auth
|
41
|
+
Use `envchain` or _.env_
|
41
42
|
|
42
43
|
```
|
43
44
|
amazon_auth
|
44
45
|
|
46
|
+
envchain amazon ...
|
47
|
+
# OR
|
45
48
|
vi .env
|
46
49
|
```
|
47
50
|
|
@@ -53,7 +56,7 @@ In console
|
|
53
56
|
|
54
57
|
```ruby
|
55
58
|
require 'amazon_order'
|
56
|
-
client = AmazonOrder::Client.new(verbose: true, limit: 10)
|
59
|
+
client = AmazonOrder::Client.new(keep_cookie: true, verbose: true, limit: 10)
|
57
60
|
client.fetch_amazon_orders
|
58
61
|
# Fetch orders of specified year
|
59
62
|
client.fetch_orders_for_year(year: 2016)
|
@@ -65,8 +68,8 @@ client.go_to_amazon_order_page
|
|
65
68
|
client.fetch_orders_for_year(year: 2015)
|
66
69
|
```
|
67
70
|
|
68
|
-
Downloaded pages will be stored into `
|
69
|
-
|
71
|
+
Downloaded pages will be stored into `tmp/orders` directory.
|
72
|
+
`tmp` comes from `Capybara.save_path`.
|
70
73
|
|
71
74
|
Once `fetch_amazon_orders` succeeds, you can load orders information of downloaded pages anytime.
|
72
75
|
(You don't need to fetch pages with launching browser every time.)
|
@@ -86,7 +89,7 @@ products.size
|
|
86
89
|
orders.group_by{|o| o.order_placed.strftime('%Y') }.sort_by{|year,_| year }.map{|year,records| puts [year, records.map(&:order_total).sum].inspect };nil
|
87
90
|
```
|
88
91
|
|
89
|
-
Example of data
|
92
|
+
#### Example of data
|
90
93
|
|
91
94
|
```ruby
|
92
95
|
console> pp orders.first.to_hash
|
@@ -111,16 +114,24 @@ console> pp products.first.to_hash
|
|
111
114
|
"https://images-fe.ssl-images-amazon.com/images/I/51TODrMIEnL.jpg"}
|
112
115
|
```
|
113
116
|
|
117
|
+
#### Export csv
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
client.generate_csv
|
121
|
+
```
|
122
|
+
|
114
123
|
#### Options
|
115
124
|
|
116
125
|
Limit fetching with number of pages: `client = AmazonOrder::Client.new(limit: 5)`
|
117
|
-
`limit: nil` for no limit. default is 5
|
126
|
+
(`limit: nil` for no limit. default is 5)
|
118
127
|
|
119
128
|
Set year range: `client = AmazonOrder::Client.new(year_from: 2012, year_to: 2013)`
|
120
|
-
default is Time.current.year
|
129
|
+
(default is Time.current.year)
|
121
130
|
|
122
131
|
##### Options of amazon_auth gem
|
123
132
|
|
133
|
+
Keep cookies(keep signin): `keep_cookie: true`
|
134
|
+
|
124
135
|
Firefox: `driver: :firefox`
|
125
136
|
|
126
137
|
Output debug log: `debug: true`
|
data/amazon_order.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_runtime_dependency "amazon_auth", "~> 0.
|
24
|
+
spec.add_runtime_dependency "amazon_auth", "~> 0.4.0"
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.14"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
data/lib/amazon_order/client.rb
CHANGED
@@ -6,11 +6,14 @@ module AmazonOrder
|
|
6
6
|
|
7
7
|
def initialize(options = {})
|
8
8
|
@options = options
|
9
|
-
@base_dir = @options.fetch(:base_dir, 'orders')
|
10
9
|
@client = AmazonAuth::Client.new(@options)
|
11
10
|
extend(AmazonAuth::SessionExtension)
|
12
11
|
end
|
13
12
|
|
13
|
+
def base_dir
|
14
|
+
options.fetch(:base_dir, 'orders')
|
15
|
+
end
|
16
|
+
|
14
17
|
def year_from
|
15
18
|
options.fetch(:year_from, Time.current.year)
|
16
19
|
end
|
@@ -37,7 +40,7 @@ module AmazonOrder
|
|
37
40
|
|
38
41
|
def load_amazon_orders
|
39
42
|
orders = []
|
40
|
-
Dir.glob(
|
43
|
+
Dir.glob(file_glob_pattern).each do |filepath|
|
41
44
|
log "Loading #{filepath}"
|
42
45
|
parser = AmazonOrder::Parser.new(filepath)
|
43
46
|
orders += parser.orders
|
@@ -45,6 +48,18 @@ module AmazonOrder
|
|
45
48
|
orders.sort_by{|o| -o.fetched_at.to_i }.uniq(&:order_number)
|
46
49
|
end
|
47
50
|
|
51
|
+
def file_glob_pattern
|
52
|
+
File.join(Capybara.save_path, base_dir, '*html')
|
53
|
+
end
|
54
|
+
|
55
|
+
def generate_csv
|
56
|
+
writer.generate_csv
|
57
|
+
end
|
58
|
+
|
59
|
+
def writer
|
60
|
+
@_writer ||= AmazonOrder::Writer.new(file_glob_pattern)
|
61
|
+
end
|
62
|
+
|
48
63
|
def sign_in
|
49
64
|
@client.sign_in
|
50
65
|
end
|
@@ -83,7 +98,7 @@ module AmazonOrder
|
|
83
98
|
def save_page_for(year, page)
|
84
99
|
log "Saving year:#{year} page:#{page}"
|
85
100
|
path = ['order', year.to_s, "p#{page}", Time.current.strftime('%Y%m%d%H%M%S')].join('-') + '.html'
|
86
|
-
session.save_page(File.join(
|
101
|
+
session.save_page(File.join(base_dir, path))
|
87
102
|
end
|
88
103
|
|
89
104
|
def selected_year
|
data/lib/amazon_order/version.rb
CHANGED
data/lib/amazon_order/writer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module AmazonOrder
|
2
2
|
class Writer
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(file_glob_pattern, options = {})
|
4
|
+
@file_glob_pattern = file_glob_pattern
|
5
5
|
@output_dir = options.fetch(:output_dir, 'tmp')
|
6
6
|
end
|
7
7
|
|
@@ -32,7 +32,7 @@ module AmazonOrder
|
|
32
32
|
def data
|
33
33
|
@_data ||= begin
|
34
34
|
data = {'orders' => [], 'products' => []}
|
35
|
-
Dir.glob(
|
35
|
+
Dir.glob(@file_glob_pattern).each do |filepath|
|
36
36
|
puts " Parsing #{filepath}"
|
37
37
|
parser = AmazonOrder::Parser.new(filepath)
|
38
38
|
data['orders'] += parser.orders.map(&:values)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon_order
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuho Yamaguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazon_auth
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.4.0
|
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
|
-
version: 0.
|
26
|
+
version: 0.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|