#!/usr/bin/perl use strict; use warnings; use diagnostics; use File::Find; use Date::Format; use Date::Parse; sub process { if (-f $_ && /\.html$/) { my $fn = $_; open(F, "<:utf8", $fn) or die("Cannot open ${File::Find::name}: $!"); my ($in_text, $in_subject) = undef; my ($text, $subject, $time); while () { chomp; if ($_ =~ /\w+, (\w+ \d\d, \d{4})/) { $time = str2time($1); } elsif (/

/) { # Subject $in_subject = 1; } elsif ($in_subject && $_ !~ m%

%) { $subject = $_ if /\w/; } elsif ($in_subject && $_ =~ m%%) { $in_subject = undef; $text = "$subject\n"; } elsif (/
/) { # Text $in_text = 1; } elsif ($in_text && $_ !~ m%
%) { $text .= $_ . "\n"; } elsif ($in_text && $_ =~ m%%) { last; } } die "Invalid fileformat: $text $time." unless ($text && $time); $text =~ s/(\r|

|<\/p>|^\s*)//gm; $fn =~ s/html$/txt/; open(OUT, ">:encoding(iso-8859-15)", "/home/hynek/old-blog/new/$fn") or die "Cannot open for write: $!."; print OUT $text; close(OUT); utime $time, $time, ("/home/hynek/old-blog/new/$fn"); } } find(\&process, ("tmp"));