Compare commits
2 commits
882c06bcda
...
2de772a51b
Author | SHA1 | Date | |
---|---|---|---|
|
2de772a51b | ||
|
f018f221ad |
11
README.md
11
README.md
|
@ -5,7 +5,7 @@ personal use here.
|
|||
|
||||
## Perl
|
||||
|
||||
### mmm.pl
|
||||
### [mmm.pl](mmm/mmm.pl)
|
||||
|
||||
`mmm` (*MIME multipart/alternative from Markdown*) can
|
||||
create a MIME `multipart/alternative` mail, containing a
|
||||
|
@ -15,7 +15,7 @@ can be prepended from a template file.
|
|||
|
||||
Usage: `mmm [--file $inputfile] [--headers $templatefile]`
|
||||
|
||||
### footnotes.pl
|
||||
### [footnotes.pl](converters/footnotes.pl)
|
||||
|
||||
`footnotes` will convert footnotes in MultiMarkDown format
|
||||
to the format of the Wordpress plugin
|
||||
|
@ -23,3 +23,10 @@ to the format of the Wordpress plugin
|
|||
|
||||
Usage: `footnotes --to mmd|wp [--file $inputfile]`
|
||||
|
||||
### [pocket-raindrop.pl](converters/pocket-raindrop.pl)
|
||||
|
||||
`pocket-raindrop` will reformat a CSV export file from
|
||||
[Pocket](https://getpocket.com/) into a CSV import file for
|
||||
[Raindrop](https://raindrop.io/).
|
||||
|
||||
Usage: `pocket-raindrop part_000000.csv`, output to `raindrop.csv`.
|
||||
|
|
100
converters/pocket-raindrop.pl
Normal file
100
converters/pocket-raindrop.pl
Normal file
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
# pocket-raindrop.pl
|
||||
#
|
||||
# Reformat a CSV export file from Pocket <https://getpocket.com/>
|
||||
# into a CSV import file for Raindrop <https://raindrop.io/>.
|
||||
#
|
||||
# - 'time_added' is renamed to 'created'
|
||||
# - empty 'note' entries are added
|
||||
# - tags are reformatted (from tag1|tag2 to "tag1, tag2")
|
||||
# - 'unread'/'archive' status is moved to an 'unread' or 'archive'
|
||||
# tag, as Raindrop does not have this status.
|
||||
#
|
||||
# Usage: 'pocket-raindrop.pl <IMPORTFILE>', e.g.
|
||||
# $ pocket-raindrop.pl part_000000.csv
|
||||
#
|
||||
# Output is written to 'raindrop.csv'.
|
||||
#
|
||||
# Copyright (c) 2025 Thomas Hochstein <thh@thh.name>
|
||||
#
|
||||
# This file can be redistributed and/or modified under the same terms
|
||||
# under which Perl itself is published.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Text::CSV; # from CPAN / apt install libtext-csv-perl
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# new CVS object
|
||||
my $csv = Text::CSV->new;
|
||||
|
||||
# ----------------------------------------
|
||||
# get $inputfile from command line argument
|
||||
my $inputfile = shift(@ARGV);
|
||||
open my $fh, "<:encoding(UTF-8)", $inputfile or die "inputfile: $!";
|
||||
|
||||
# get column names
|
||||
my @fieldlist = @{$csv->getline ($fh)};
|
||||
$csv->column_names (@fieldlist);
|
||||
|
||||
# read CSV
|
||||
my @rows;
|
||||
while (my $row = $csv->getline_hr ($fh)) {
|
||||
# parse and modify CSV
|
||||
if ($row->{'url'}) {
|
||||
my @tags;
|
||||
|
||||
# move 'time_added' to 'created'
|
||||
$row->{'created'} = $row->{'time_added'};
|
||||
delete($row->{'time_added'});
|
||||
|
||||
# add empty 'note'
|
||||
$row->{'note'} = '';
|
||||
|
||||
# move status ('read'/'unread') to tags
|
||||
if ($row->{'status'}) {
|
||||
push @tags, $row->{'status'};
|
||||
delete($row->{'status'});
|
||||
}
|
||||
|
||||
# add 'twitter' tag for 't.co' URLs
|
||||
# if ($row->{'url'} =~ m!^http://t\.co/!) {
|
||||
# push @tags, 'twitter';
|
||||
# }
|
||||
|
||||
# reformat current tags
|
||||
if ($row->{'tags'} =~ /\|/) {
|
||||
push @tags, split(/\|/,$row->{'tags'});
|
||||
} elsif ($row->{'tags'}) {
|
||||
push @tags, $row->{'tags'};
|
||||
}
|
||||
|
||||
# rewrite tags from @tags
|
||||
if (@tags) {
|
||||
$row->{'tags'} = join(', ', @tags);
|
||||
}
|
||||
|
||||
# add to result array for output
|
||||
push @rows, $row;
|
||||
}
|
||||
}
|
||||
|
||||
close $fh;
|
||||
|
||||
# ----------------------------------------
|
||||
# write new CSV to raindrop.csv
|
||||
@fieldlist = qw/title url created tags note/;
|
||||
$csv->column_names (@fieldlist);
|
||||
|
||||
open $fh, ">:encoding(UTF-8)", 'raindrop.csv' or die "raindrop.csv: $!";
|
||||
|
||||
print $fh (join(',', @fieldlist)), "\n";
|
||||
|
||||
foreach (@rows) {
|
||||
$csv->print_hr ($fh, $_);
|
||||
print $fh "\n";
|
||||
}
|
||||
|
||||
close $fh;
|
Loading…
Reference in a new issue