| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Amazon::Recommended; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
764
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
39
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Grab and configurate recommendations by Amazon |
|
7
|
|
|
|
|
|
|
our $VERSION = 'v0.0.3'; # VERSION |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
11
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
68
|
|
|
10
|
1
|
|
|
1
|
|
862
|
use Template::Extract; |
|
|
1
|
|
|
|
|
746
|
|
|
|
1
|
|
|
|
|
31
|
|
|
11
|
1
|
|
|
1
|
|
1164
|
use DateTime::Format::Strptime; |
|
|
1
|
|
|
|
|
238083
|
|
|
|
1
|
|
|
|
|
81
|
|
|
12
|
1
|
|
|
1
|
|
1067
|
use Data::Section -setup; |
|
|
1
|
|
|
|
|
42659
|
|
|
|
1
|
|
|
|
|
9
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new |
|
15
|
|
|
|
|
|
|
{ |
|
16
|
1
|
|
|
1
|
1
|
469
|
my $self = shift; |
|
17
|
1
|
|
33
|
|
|
10
|
my $class = ref $self || $self; |
|
18
|
1
|
|
|
|
|
3
|
my %args = @_; |
|
19
|
1
|
50
|
33
|
|
|
32
|
croak 'email andd password are required' if ! exists $args{email} || ! exists $args{password}; |
|
20
|
0
|
|
0
|
|
|
|
$args{domain} ||= 'co.jp'; |
|
21
|
0
|
|
|
|
|
|
return bless { |
|
22
|
|
|
|
|
|
|
_DOMAIN => $args{domain}, |
|
23
|
|
|
|
|
|
|
_MECH => join('::', __PACKAGE__, 'Mechanize')->new( |
|
24
|
|
|
|
|
|
|
email => $args{email}, |
|
25
|
|
|
|
|
|
|
password => $args{password}, |
|
26
|
|
|
|
|
|
|
domain => $args{domain}, |
|
27
|
|
|
|
|
|
|
), |
|
28
|
|
|
|
|
|
|
}, $class; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# URL: /gp/yourstore//ref=pd_ys_?rGroup= |
|
32
|
|
|
|
|
|
|
# type: recs (All), nr (New Release), fr (Coming soon) |
|
33
|
|
|
|
|
|
|
# category, category_: depends on domain |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my (%format) = ( |
|
36
|
|
|
|
|
|
|
'co.jp' => ['%Y/%m/%d', '%Y/%m'], |
|
37
|
|
|
|
|
|
|
'' => ['%B %d, %Y', '%B %Y'], |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $NOTFOUND_REGEX = ${__PACKAGE__->section_data('NOTFOUND_REGEX')}; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# TODO: more relaxed template |
|
43
|
|
|
|
|
|
|
# TODO: there might be not date |
|
44
|
|
|
|
|
|
|
my $extractor = Template::Extract->new; |
|
45
|
|
|
|
|
|
|
my $EXTRACT_REGEX = $extractor->compile(${__PACKAGE__->section_data('EXTRACT_RECS_TMPL')}); |
|
46
|
|
|
|
|
|
|
my $EXTRACT_STATUS_REGEX = $extractor->compile(${__PACKAGE__->section_data('EXTRACT_STATUS_TMPL')}); |
|
47
|
|
|
|
|
|
|
my $EXTRACT_LIST_REGEX = $extractor->compile(${__PACKAGE__->section_data('EXTRACT_LIST_TMPL')}); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my %URL = ( |
|
50
|
|
|
|
|
|
|
root => '/', |
|
51
|
|
|
|
|
|
|
login => '/gp/sign-in.html', |
|
52
|
|
|
|
|
|
|
logout => '/gp/flex/sign-out.html', |
|
53
|
|
|
|
|
|
|
rate => '/gp/rate-it/ref=pd_ys_wizard_search?rateIndex=search-alias%3Daps&rateKeywords=', |
|
54
|
|
|
|
|
|
|
submit => '/gp/yourstore/ratings/submit.html/ref=pd_recs_rate_dp_ys_ir_all', |
|
55
|
|
|
|
|
|
|
owned => '/gp/yourstore/iyr/ref=pd_ys_iyr_edit_own?ie=UTF8&collection=owned', |
|
56
|
|
|
|
|
|
|
notinterested => '/gp/yourstore/iyr/ref=pd_ys_iyr_edit_notInt?ie=UTF8&collection=notInt', |
|
57
|
|
|
|
|
|
|
rated => '/gp/yourstore/iyr/ref=pd_ys_iyr_edit_rated?ie=UTF8&collection=rated', |
|
58
|
|
|
|
|
|
|
purchased => '/gp/yourstore/iyr?ie=UTF8&collection=purchased', |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my %VALID = ( |
|
62
|
|
|
|
|
|
|
rate => [qw(itemId starRating isOwned)], |
|
63
|
|
|
|
|
|
|
owned => [qw(itemId starRating isExcluded)], |
|
64
|
|
|
|
|
|
|
notinterested => [qw(itemId isNotInterested)], |
|
65
|
|
|
|
|
|
|
rated => [qw(itemId starRating isExcluded)], |
|
66
|
|
|
|
|
|
|
purchased => [qw(itemId starRating isExcluded)], |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _url |
|
70
|
|
|
|
|
|
|
{ |
|
71
|
0
|
|
|
0
|
|
|
my ($self, $type) = @_; |
|
72
|
0
|
|
|
|
|
|
return 'https://www.amazon.'.$self->{_DOMAIN}.$URL{lc $type}; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
0
|
|
|
0
|
1
|
|
my ($self, $url, $max_pages) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $mech = $self->{_MECH}; |
|
80
|
0
|
0
|
|
|
|
|
$mech->login() or die 'login failed'; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $content; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
my $pages = @_ >= 3 ? $max_pages : 1; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
my $key = exists $format{$self->{_DOMAIN}} ? $self->{_DOMAIN} : ''; |
|
87
|
0
|
|
|
|
|
|
my (@strp) = map { DateTime::Format::Strptime->new(pattern => $_) } @{$format{$key}}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $result = []; |
|
90
|
0
|
|
0
|
|
|
|
while(! defined $pages || --$pages >= 0) { |
|
91
|
0
|
0
|
|
|
|
|
if(defined $content) { # Successive invocation |
|
92
|
0
|
|
|
|
|
|
$content = $mech->next(); |
|
93
|
|
|
|
|
|
|
} else { # First invocation |
|
94
|
0
|
|
|
|
|
|
$content = $mech->get($url); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
0
|
0
|
|
|
|
|
last if ! defined $content; # Can't get content because next link does not exist, or some reasons |
|
97
|
0
|
0
|
|
|
|
|
last if $content =~ /$NOTFOUND_REGEX/; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $source = $extractor->run($EXTRACT_REGEX, $content); |
|
100
|
0
|
0
|
0
|
|
|
|
croak 'Non existent category' if $url =~ /\b(rGroup|nodeId)\b/ && $source->{category} eq ''; |
|
101
|
0
|
|
|
|
|
|
foreach my $data (@{$source->{entry}}) { |
|
|
0
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$data->{author} =~ s/^\s+//; |
|
103
|
0
|
|
|
|
|
|
$data->{author} =~ s/\s+$//; |
|
104
|
0
|
|
|
|
|
|
my $root = $self->_url('root'); |
|
105
|
0
|
|
|
|
|
|
$root =~ s,^https://,,; |
|
106
|
0
|
|
|
|
|
|
$data->{url} =~ s,\Q$root\E.*/dp/,${root}dp/,; |
|
107
|
0
|
|
|
|
|
|
$data->{url} =~ s,/ref=[^/]*$,,; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Damn..., I can't make correct Template::Extract template, so making use of regexp |
|
110
|
0
|
|
|
|
|
|
my $price = delete $data->{pricebox}; |
|
111
|
0
|
0
|
|
|
|
|
if($price =~ m|([^<]*)|) { |
|
112
|
0
|
|
|
|
|
|
$data->{listprice} = $1; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
0
|
0
|
|
|
|
|
if($price =~ m|([^<]*)|) { |
|
115
|
0
|
|
|
|
|
|
$data->{price} = $1; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
0
|
0
|
|
|
|
|
if($price =~ m|([^<]*)|) { |
|
118
|
0
|
|
|
|
|
|
$data->{otherprice} = $1; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $date; |
|
122
|
0
|
|
|
|
|
|
foreach my $strp (@strp) { |
|
123
|
0
|
|
|
|
|
|
$date = $strp->parse_datetime($data->{date}); |
|
124
|
0
|
0
|
|
|
|
|
last if defined $date; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
0
|
0
|
|
|
|
|
$data->{date} = $date if defined $date; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
0
|
|
|
|
|
|
push @$result, @{$source->{entry}}; |
|
|
0
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
|
130
|
0
|
|
|
|
|
|
return $result; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub get_list |
|
134
|
|
|
|
|
|
|
{ |
|
135
|
0
|
|
|
0
|
1
|
|
my ($self, $type, $max_pages) = @_; |
|
136
|
0
|
|
|
|
|
|
my $url = $self->_url($type); |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
my $mech = $self->{_MECH}; |
|
139
|
0
|
0
|
|
|
|
|
$mech->login() or die 'login failed'; |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $content; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
0
|
|
|
|
|
my $pages = @_ >= 3 ? $max_pages : 1; |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my $result = []; |
|
146
|
0
|
|
0
|
|
|
|
while(! defined $pages || --$pages >= 0) { |
|
147
|
0
|
0
|
|
|
|
|
if(defined $content) { # Successive invocation |
|
148
|
0
|
|
|
|
|
|
$content = $mech->next(); |
|
149
|
|
|
|
|
|
|
} else { # First invocation |
|
150
|
0
|
|
|
|
|
|
$content = $mech->get($url); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
0
|
0
|
|
|
|
|
last if ! defined $content; # Can't get content because next link does not exist, or some reasons |
|
153
|
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my $source = $extractor->run($EXTRACT_LIST_REGEX, $content); |
|
155
|
0
|
|
|
|
|
|
foreach my $data (@{$source->{entry}}) { |
|
|
0
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$data->{author} =~ s/^\s+//; |
|
157
|
0
|
|
|
|
|
|
$data->{author} =~ s/\s+$//; |
|
158
|
0
|
|
|
|
|
|
my $root = $self->_url('root'); |
|
159
|
0
|
|
|
|
|
|
$root =~ s,^https://,,; |
|
160
|
0
|
|
|
|
|
|
$data->{url} =~ s,\Q$root\E.*/dp/,${root}dp/,; |
|
161
|
0
|
|
|
|
|
|
$data->{url} =~ s,/ref=[^/]*$,,; |
|
162
|
|
|
|
|
|
|
# It looks like easy thing to handle inside Template::Extract, but I can't achieve it... |
|
163
|
0
|
|
|
|
|
|
my (%result) = map { /^\s*(\S*)\s*$/; } map { split /:/ } split /,/, delete $data->{values}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$data->{$_} = $result{$_} for @{$VALID{lc $type}}; |
|
|
0
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
} |
|
166
|
0
|
|
|
|
|
|
push @$result, @{$source->{entry}}; |
|
|
0
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
|
168
|
0
|
|
|
|
|
|
return $result; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _get_status |
|
172
|
|
|
|
|
|
|
{ |
|
173
|
0
|
|
|
0
|
|
|
my ($self, $type, $url) = @_; |
|
174
|
0
|
|
|
|
|
|
my $mech = $self->{_MECH}; |
|
175
|
0
|
0
|
|
|
|
|
$mech->login() or die 'login failed'; |
|
176
|
0
|
|
|
|
|
|
my $content = $mech->get($url); |
|
177
|
|
|
|
|
|
|
# It looks like easy thing to handle inside Template::Extract, but I can't achieve it... |
|
178
|
0
|
|
|
|
|
|
my $source = $extractor->run($EXTRACT_STATUS_REGEX, $content); |
|
179
|
0
|
0
|
|
|
|
|
return if ! exists $source->{values}; |
|
180
|
0
|
|
|
|
|
|
my (%result) = map { /^\s*(\S*)\s*$/; } map { split /:/ } split /,/, $source->{values}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
return { map { $_ => $result{$_} } @{$VALID{lc $type}} }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub get_status |
|
185
|
|
|
|
|
|
|
{ |
|
186
|
0
|
|
|
0
|
1
|
|
my ($self, $asin) = @_; |
|
187
|
0
|
|
|
|
|
|
return $self->_get_status('rate', $self->_url('rate').$asin); |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub get_last_status |
|
191
|
|
|
|
|
|
|
{ |
|
192
|
0
|
|
|
0
|
1
|
|
my ($self, $type) = @_; |
|
193
|
0
|
|
|
|
|
|
return $self->_get_status($type, $self->_url($type)); |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
my %PARAM = ( |
|
197
|
|
|
|
|
|
|
starRating => ['onetofive',[0,1,2,3,4,5]], |
|
198
|
|
|
|
|
|
|
isNotInterested => ['not-interested', ['NONE', 'NOTINTERESTED']], |
|
199
|
|
|
|
|
|
|
isOwned => ['owned',['NONE', 'OWN']], |
|
200
|
|
|
|
|
|
|
isExcluded => ['excluded',['NONE', 'EXCLUDED']], |
|
201
|
|
|
|
|
|
|
isExcludedClickstream => ['excludedClickstream', ['NONE', 'EXCLUDED']], |
|
202
|
|
|
|
|
|
|
isGift => ['isGift', ['NONE', 'ISGIFT']], |
|
203
|
|
|
|
|
|
|
isPreferred => ['isPreferred', ['NONE', 'ISPREFERRED']], |
|
204
|
|
|
|
|
|
|
); |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub set_status |
|
207
|
|
|
|
|
|
|
{ |
|
208
|
0
|
|
|
0
|
1
|
|
my ($self, $asin, $param) = @_; |
|
209
|
0
|
|
|
|
|
|
my $mech = $self->{_MECH}; |
|
210
|
0
|
0
|
|
|
|
|
$mech->login() or die 'login failed'; |
|
211
|
0
|
|
|
|
|
|
my $dat = { |
|
212
|
|
|
|
|
|
|
rating_asin => $asin, |
|
213
|
|
|
|
|
|
|
'rating.source' => 'ir', |
|
214
|
|
|
|
|
|
|
type => 'asin', |
|
215
|
|
|
|
|
|
|
'return.response' => '204', |
|
216
|
|
|
|
|
|
|
'template-name' => '/gp/yourstore/recs/ref=pd_ys_welc', |
|
217
|
|
|
|
|
|
|
}; |
|
218
|
0
|
|
|
|
|
|
foreach my $key (keys %$param) { |
|
219
|
0
|
0
|
|
|
|
|
if(exists $PARAM{$key}) { |
|
220
|
0
|
|
|
|
|
|
$dat->{$asin.'_asin.rating.'.$PARAM{$key}[0]} = $PARAM{$key}[1][$param->{$key}]; |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
} |
|
223
|
0
|
|
|
|
|
|
my $content = $mech->post($self->_url('submit'), $dat); |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
package Net::Amazon::Recommended::Mechanize; |
|
227
|
|
|
|
|
|
|
|
|
228
|
1
|
|
|
1
|
|
2381
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
229
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
230
|
|
|
|
|
|
|
|
|
231
|
1
|
|
|
1
|
|
1873
|
use WWW::Mechanize; |
|
|
1
|
|
|
|
|
208383
|
|
|
|
1
|
|
|
|
|
676
|
|
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub _url |
|
234
|
|
|
|
|
|
|
{ |
|
235
|
0
|
|
|
0
|
|
|
my ($self, $type) = @_; |
|
236
|
0
|
|
|
|
|
|
return 'https://www.amazon.'.$self->{_DOMAIN}.$URL{lc $type}; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub new |
|
240
|
|
|
|
|
|
|
{ |
|
241
|
0
|
|
|
0
|
|
|
my ($self, %args) = @_; |
|
242
|
0
|
|
0
|
|
|
|
my $class = ref $self || $self; |
|
243
|
0
|
|
|
|
|
|
my $mech = WWW::Mechanize->new; |
|
244
|
0
|
|
|
|
|
|
$mech->agent_alias('Windows IE 6'); # Without this line, sign-in is not done |
|
245
|
0
|
|
|
|
|
|
return bless { |
|
246
|
|
|
|
|
|
|
_MECH => $mech, |
|
247
|
|
|
|
|
|
|
_EMAIL => $args{email}, |
|
248
|
|
|
|
|
|
|
_PASSWORD => $args{password}, |
|
249
|
|
|
|
|
|
|
_DOMAIN => $args{domain}, |
|
250
|
|
|
|
|
|
|
_IS_LOGIN => 0, |
|
251
|
|
|
|
|
|
|
}, $class; |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub is_login |
|
255
|
|
|
|
|
|
|
{ |
|
256
|
0
|
|
|
0
|
|
|
my ($self, $value) = @_; |
|
257
|
0
|
0
|
|
|
|
|
$self->{_IS_LOGIN} = $value if defined $value; |
|
258
|
0
|
|
|
|
|
|
return $self->{_IS_LOGIN}; |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub login |
|
262
|
|
|
|
|
|
|
{ |
|
263
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
264
|
0
|
0
|
|
|
|
|
return 1 if $self->is_login(); # TODO: handle expiration |
|
265
|
0
|
|
|
|
|
|
my $mech = $self->{_MECH}; |
|
266
|
0
|
|
|
|
|
|
$mech->get($self->_url('login')); |
|
267
|
0
|
|
|
|
|
|
$mech->submit_form( |
|
268
|
|
|
|
|
|
|
form_name => 'sign-in', |
|
269
|
|
|
|
|
|
|
fields => { |
|
270
|
|
|
|
|
|
|
email => $self->{_EMAIL}, |
|
271
|
|
|
|
|
|
|
password => $self->{_PASSWORD}, |
|
272
|
|
|
|
|
|
|
}, |
|
273
|
|
|
|
|
|
|
); |
|
274
|
0
|
|
|
|
|
|
my $url = $self->_url('logout'); $url =~ s/^https/http/; |
|
|
0
|
|
|
|
|
|
|
|
275
|
0
|
0
|
|
|
|
|
return if $mech->content() !~ /\Q$url\E/; |
|
276
|
0
|
|
|
|
|
|
$self->is_login(1); |
|
277
|
0
|
|
|
|
|
|
return 1; |
|
278
|
|
|
|
|
|
|
} |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
sub get |
|
281
|
|
|
|
|
|
|
{ |
|
282
|
0
|
|
|
0
|
|
|
my ($self, $url) = @_; |
|
283
|
0
|
|
|
|
|
|
my $mech = $self->{_MECH}; |
|
284
|
0
|
0
|
|
|
|
|
$self->login() or return; |
|
285
|
0
|
|
|
|
|
|
$mech->get($url); |
|
286
|
0
|
|
|
|
|
|
return $mech->content(); |
|
287
|
|
|
|
|
|
|
} |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
sub next |
|
290
|
|
|
|
|
|
|
{ |
|
291
|
0
|
|
|
0
|
|
|
my ($self, $url) = @_; |
|
292
|
0
|
|
|
|
|
|
my $mech = $self->{_MECH}; |
|
293
|
0
|
0
|
|
|
|
|
if($mech->content =~ m||) { |
|
|
|
0
|
|
|
|
|
|
|
294
|
0
|
|
|
|
|
|
my $url = $1; |
|
295
|
0
|
|
|
|
|
|
$url =~ s/&/&/g; |
|
296
|
0
|
|
|
|
|
|
$mech->get($url); |
|
297
|
0
|
|
|
|
|
|
return $mech->content(); |
|
298
|
0
|
|
|
|
|
|
} elsif(defined eval { $mech->follow_link(url_regex => qr/pd_ys_next/) }) { |
|
299
|
0
|
|
|
|
|
|
return $mech->content(); |
|
300
|
|
|
|
|
|
|
} else { |
|
301
|
0
|
|
|
|
|
|
return; |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
sub post |
|
306
|
|
|
|
|
|
|
{ |
|
307
|
0
|
|
|
0
|
|
|
my ($self, $url, $param) = @_; |
|
308
|
0
|
|
|
|
|
|
my $mech = $self->{_MECH}; |
|
309
|
0
|
0
|
|
|
|
|
$self->login() or return; |
|
310
|
|
|
|
|
|
|
$mech->cookie_jar->scan(sub { |
|
311
|
0
|
0
|
|
0
|
|
|
$param->{'session-id'} = $_[2] if $_[1] eq 'session-id'; |
|
312
|
0
|
|
|
|
|
|
}); |
|
313
|
0
|
|
|
|
|
|
$mech->post($url, $param); |
|
314
|
0
|
|
|
|
|
|
return $mech->content(); |
|
315
|
|
|
|
|
|
|
} |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
package Net::Amazon::Recommended; |
|
318
|
|
|
|
|
|
|
1; |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=pod |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=head1 NAME |
|
323
|
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
Net::Amazon::Recommended - Grab and configurate recommendations by Amazon |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=head1 VERSION |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
version v0.0.3 |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
my $obj = Net::Amazon::Recommended->new( |
|
333
|
|
|
|
|
|
|
email => 'someone@example.com', |
|
334
|
|
|
|
|
|
|
password => 'password', |
|
335
|
|
|
|
|
|
|
domain => 'co.jp', |
|
336
|
|
|
|
|
|
|
); |
|
337
|
|
|
|
|
|
|
my $rec = $obj->get('http://www.amazon.co.jp/gp/yourstore/recs/ref=pd_ys_welc'); |
|
338
|
|
|
|
|
|
|
print join "\n", map { $_->{title} } @$rec; |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
This module obtains recommended items in Amazon by using L. |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
To spcify category, you need to specify URL itself. To specify some constants or short-hand key is considered |
|
345
|
|
|
|
|
|
|
but currently rejected because category names are dependent on domains and it is difficult to enumerate all |
|
346
|
|
|
|
|
|
|
possible sub categories. |
|
347
|
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=head1 METHODS |
|
349
|
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
=head2 new(C<%options>) |
|
351
|
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
Constructor. The following options are available. |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
=over 4 |
|
355
|
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
=item email =E $email |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
Specify an email as a login ID. |
|
359
|
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=item password =E $password |
|
361
|
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
Specify a password. |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=item domain =E $domain |
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
Domain of Amazon e.g. C<'com'>. Defaults to C<'co.jp'>. C<'com'>, C<'co.uk'> and C<'co.jp'> are checked. It might work for other domains. |
|
367
|
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
=back |
|
369
|
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
=head2 get(C<$url>, C<$max_pages> = 1) |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
Returns array reference of recommended items. |
|
373
|
|
|
|
|
|
|
Each element is a hash reference having the following keys: |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
=over 4 |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=item C |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
ASIN ID. |
|
380
|
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
=item C |
|
382
|
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
URL for the item like http://www.amazon.co.jp/dp/4873110963. Just an ASIN is used and other components are stripped. |
|
384
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
=item C |
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
URL of cover image. |
|
388
|
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
=item C |
|
390
|
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
Title. |
|
392
|
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
=item author |
|
394
|
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
Author. |
|
396
|
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
=item date |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
L object of publish date. |
|
400
|
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
=item price |
|
402
|
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
price in just a string. Currency symbol is included. |
|
404
|
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
=item listprice |
|
406
|
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
list price in just a string. Currency symbol is included. |
|
408
|
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
=item otherprice |
|
410
|
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
price by other sellers in just a string. Currency symbol is included. |
|
412
|
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
=back |
|
414
|
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
C<$url> can be sub category page like http://www.amazon.co.jp/gp/yourstore/recs/ref=pd_ys_nav_b_515826?ie=UTF8&nodeID=515826&parentID=492352&parentStoreNode=492352. |
|
416
|
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
C<$max_page> is the limitation of retrieving pages. Defaults to 1. To specify C B means no limitation, that is all recommended items are retrieved. |
|
418
|
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
=head2 get_list(C<$type>, C<$max_pages> = 1) |
|
420
|
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
Returns array reference of items in the specified type. C<$type> can be C<'notinterested'>, C<'owned'>, C<'purchased'> or C<'rated'>. |
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
Each element is a hash reference having the following keys: |
|
424
|
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
=over 4 |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=item C |
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
ASIN ID. |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
=item C |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
URL for the item like http://www.amazon.co.jp/dp/4873110963. Just an ASIN is used and other components are stripped. |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
=item C |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
URL of cover image. |
|
438
|
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
=item C |
|
440
|
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
Title. |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
=item author |
|
444
|
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
Author. It might be empty. |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
=item C |
|
448
|
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
Rated value for this item from 1 to 5. 0 means not rated. |
|
450
|
|
|
|
|
|
|
This key is avaiable for the case that C<$type> is C<'owned'>, C<'purchased'> or C<'rated'>. |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
=item C |
|
453
|
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
1 means this item is not interested. 0 means not. |
|
455
|
|
|
|
|
|
|
This key is avaiable for the case that C<$type> is C<'notinterested'>. |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
=item C |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
1 means this item is not considered for recommendation. 0 means considered. |
|
460
|
|
|
|
|
|
|
This key is avaiable for the case that C<$type> is C<'owned'>, C<'purchased'> or C<'rated'>. |
|
461
|
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
=back |
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
C<$max_page> is the limitation of retrieving pages. Defaults to 1. To specify C B means no limitation, that is all recommended items are retrieved. |
|
465
|
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
=head2 get_status(C<$asin>) |
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
Returns a hash reference having the following keys. If the corresponding item is not found, C is returned. |
|
469
|
|
|
|
|
|
|
B, it seems to be that only C<'co.jp'> provides the interface C used by this method. |
|
470
|
|
|
|
|
|
|
Other domains moved to /gp/betterizer/ intefrace. |
|
471
|
|
|
|
|
|
|
To set some state by C then calling C or C might be used as workaround. |
|
472
|
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
=over 4 |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
=item C |
|
476
|
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
Rated value for this item from 1 to 5. 0 means not rated. |
|
478
|
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
=item C |
|
480
|
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
1 means this item is owned. 0 means not. |
|
482
|
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
=back |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
=head2 get_last_status(C<$type>) |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
Returns a hash reference having the following keys for the last item of C<$type>. |
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
=over 4 |
|
490
|
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
=item C |
|
492
|
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
Rated value for this item from 1 to 5. 0 means not rated. |
|
494
|
|
|
|
|
|
|
This key is avaiable for the case that C<$type> is C<'owned'> or C<'rated'>. |
|
495
|
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
=item C |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
1 means this item is not interested. 0 means not. |
|
499
|
|
|
|
|
|
|
This key is avaiable for the case that C<$type> is C<'notinterested'>. |
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
=item C |
|
502
|
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
1 means this item is not considered for recommendation. 0 means considered. |
|
504
|
|
|
|
|
|
|
This key is avaiable for the case that C<$type> is C<'owned'> or C<'rated'>. |
|
505
|
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
=back |
|
507
|
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
C<$type> is case-insensitive. |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=head2 set_status(C<$asin>, C<\%args>) |
|
511
|
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
C<%arg> is a hash having some of the following keys. |
|
513
|
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
=over 4 |
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=item C |
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
Rated value for this item from 1 to 5. 0 means not rated. |
|
519
|
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=item C |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
1 means this item is owned. 0 means not. |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
=item C |
|
525
|
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
1 means this item is not interested. 0 means not. |
|
527
|
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
=item C |
|
529
|
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
1 means this item is not considered for recommendation. 0 means considered. |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=back |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
=head1 TEST |
|
535
|
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
To test this module completely, you need to specify environment variables C and C. |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
Because results of some tests are dependent on purchase history, they are marked as TODO. |
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
B Some tests, C<03-status.t>, C<05-domain.t> and C<06-domain.t> will change your recommendation configurations. |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
543
|
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=over 4 |
|
545
|
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
=item * |
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
L |
|
549
|
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
=back |
|
551
|
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
=head1 AUTHOR |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
Yasutaka ATARASHI |
|
555
|
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
557
|
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Yasutaka ATARASHI. |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
561
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
562
|
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
=cut |
|
564
|
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
__DATA__ |