This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathamz-tradein.pl
executable file
·138 lines (75 loc) · 2.5 KB
/
amz-tradein.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env perl
#<--------------------------------- 79 chars --------------------------------->|
=pod
=head1 NAME
amz-tradein.pl
=head1 VERSION
2015-08-31 (Since 2014-11-05)
=head1 WARNING
Amazon stopped its Trade-In program on 31th August, 2015.
This script is no longer of any use.
=head1 PURPOSE
=over
=item * fetches Amazon Trade-In prices for all books in a Goodreads-shelf,
e.g., 'books-for-sale'
=item * spares you checking each book by hand every time you want to sell
books to Amazon
=item * might reveal good buyback prices for books you hadn't yet considered
for sales (run this script against a Goodreads "#ALL#" shelf)
=back
=head1 OUTPUT EXAMPLE
EUR 5,30 Book title found at Amazon with Trade-In price
EUR -,-- Book title either without Trade-In or not found by ISBN
=head1 USAGE EXAMPLE
=over
=item Check all books of a specific Goodreads user:
$ amz-tradein.pl 18418712
=item Check all books in a specific Goodreads shelf only:
$ amz-tradein.pl 18418712 books-for-sale
=item Sort by highest price and save outout to a textfile:
$ amz-tradein.pl 18418712 books-for-sale | sort --key 2n | tac > books-for-sale-w-prices.out
=back
=head1 OBSERVATIONS
=over
=item * process is slow, 123 books need ~2 minutes
=back
=head1 REQUIRES
=over
=item * a Goodreads account (number), your # is contained in each Goodreads-shelf-URL
=item * no API key
=item * $ perl -MCPAN -e 'install WWW::Curl::Easy, Cache::FileCache'
=back
=head1 KNOWN LIMITATIONS AND BUGS
=over
=item * german Amazon only (contact me if you need support for other countries)
=back
=cut
#<--------------------------------- 79 chars --------------------------------->|
use strict;
use warnings;
# Perl core:
use FindBin;
use local::lib "$FindBin::Bin/lib/local/";
use lib "$FindBin::Bin/lib/";
# Third party:
# Ours:
use Goodscrapes;
# Program synopsis:
say STDERR "Usage: $0 GOODUSERNUMBER [SHELFNAME]\nSee source code for more info." and exit if $#ARGV < 0;
# Program configuration:
our $USERID = gverifyuser ( $ARGV[0] );
our $SHELF = gverifyshelf( $ARGV[1] );
sub extract_amz_price
{
my $article_page_html = shift;
return $article_page_html =~ /(EUR [0-9,]+)<\/span> Gutschein erhalten/ ? $1 : 'EUR -,--';
}
my %books;
greadshelf( from_user_id => $USERID,
ra_from_shelves => [ $SHELF ],
rh_into => \%books );
for my $b (values %books)
{
my $price = extract_amz_price( amz_book_html( $b ) );
say STDOUT $price . "\t" . $b->{title};
}