Compare commits
No commits in common. "0539d855b5bc00a979cce6b7017c9cc09a038728" and "7a57a65e67ca1590221777c0cdc8942a28c41728" have entirely different histories.
0539d855b5
...
7a57a65e67
24
README.md
24
README.md
|
@ -5,6 +5,14 @@ personal use here.
|
||||||
|
|
||||||
## Perl
|
## Perl
|
||||||
|
|
||||||
|
### footnotes.pl
|
||||||
|
|
||||||
|
`footnotes` will convert footnotes in MultiMarkDown format
|
||||||
|
to the format of the Wordpress plugin
|
||||||
|
[footnotes](https://wordpress.org/plugins/footnotes/) and back.
|
||||||
|
|
||||||
|
Usage: `footnotes --to mmd|wp [--file $inputfile]`
|
||||||
|
|
||||||
### mmm.pl
|
### mmm.pl
|
||||||
|
|
||||||
`mmm` (*MIME multipart/alternative from Markdown*) can
|
`mmm` (*MIME multipart/alternative from Markdown*) can
|
||||||
|
@ -14,19 +22,3 @@ a Markdown file. Other mail headers (From:, To:, Subject:, ...)
|
||||||
can be prepended from a template file.
|
can be prepended from a template file.
|
||||||
|
|
||||||
Usage: `mmm [--file $inputfile] [--headers $templatefile]`
|
Usage: `mmm [--file $inputfile] [--headers $templatefile]`
|
||||||
|
|
||||||
### footnotes.pl
|
|
||||||
|
|
||||||
`footnotes` will convert footnotes in MultiMarkDown format
|
|
||||||
to the format of the Wordpress plugin
|
|
||||||
[footnotes](https://wordpress.org/plugins/footnotes/) and back.
|
|
||||||
|
|
||||||
Usage: `footnotes --to mmd|wp [--file $inputfile]`
|
|
||||||
|
|
||||||
### 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`.
|
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
#!/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