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