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
|
use 5.028;
use strict;
use warnings;
use Text::CSV_XS qw(csv);
open my $fh, ">:encoding(utf8)", "$ENV{HOME}/doc/org/goodreads_library_export.org";
my $grle = csv(
in => "$ENV{HOME}/tmp/goodreads_library_export.csv",
headers => 'auto',
encoding => 'UTF-8'
);
my (@read, @to_read);
foreach my $gr (@$grle) {
my %book = (
title => $gr->{Title},
author => $gr->{Author},
year => $gr->{'Original Publication Year'},
tags => $gr->{Bookshelves} || undef,
rating => $gr->{'My Rating'},
date_added => $gr->{'Date Added'} || undef,
date_read => $gr->{'Date Read'} || undef,
);
if ($gr->{'Exclusive Shelf'} eq 'read') {
push @read, \%book;
} elsif ($gr->{'Exclusive Shelf'} eq 'to-read') {
push @to_read, \%book;
}
}
# use Data::Dumper;
# print Dumper @read;
# print Dumper @to_read;
say $fh "Warning: This file gets overwritten by a script!";
say $fh "* To read";
foreach my $to_read (@to_read) {
say $fh "** " . $to_read->{title} . " by "
. $to_read->{author} . " ("
. $to_read->{year} . ")";
}
say $fh "* Read";
foreach my $read (@read) {
say $fh "** " . $read->{title} . " by "
. $read->{author} . " ("
. $read->{year} . ")";
say $fh "- rating :: " . $read->{rating};
if (defined $read->{tags}) {
say $fh "- tags :: " . $read->{tags};
}
if (defined $read->{date_added}) {
say $fh "- date added :: " . $read->{date_added};
}
if (defined $read->{date_read}) {
say $fh "- date read :: " . $read->{date_read};
}
}
|