|
#!/usr/bin/env perl |
|
|
|
use warnings; |
|
use strict; |
|
use LWP::Simple; |
|
use HTML::WikiConverter; |
|
use HTML::WikiConverter::Markdown; |
|
|
|
## |
|
## One time download for reading. |
|
## |
|
## [email protected] |
|
## |
|
## - xjrK |
|
|
|
## |
|
## "The Diary of Anne Frank" |
|
## |
|
|
|
# grab pages and get to reading this weekend. |
|
my ($page1, $page2, $page3, $page4, $page5); |
|
|
|
$page1 = get("http://www.fullbooks.com/A-Young-Girl-s-Diary1.html"); |
|
$page2 = get("http://www.fullbooks.com/A-Young-Girl-s-Diary2.html"); |
|
$page3 = get("http://www.fullbooks.com/A-Young-Girl-s-Diary3.html"); |
|
$page4 = get("http://www.fullbooks.com/A-Young-Girl-s-Diary4.html"); |
|
$page5 = get("http://www.fullbooks.com/A-Young-Girl-s-Diary5.html"); |
|
|
|
my @pages = ($page1, $page2, $page3, $page4, $page5); |
|
|
|
# open the diary. |
|
# "The only girl I've ever loved was born with roses in her eyes" |
|
my $diaryfile = "diary.md"; |
|
unless(open DIARY, '>>'.$diaryfile) { die "Can't write to it!"; } |
|
|
|
foreach my $page (@pages) { |
|
my $converter = new HTML::WikiConverter( dialect => 'Markdown' ); |
|
|
|
# Append to file |
|
print DIARY $converter->html2wiki($page); |
|
} |
|
# close the diary |
|
close DIARY; |
|
|
|
# "But then they buried her alive one evening, 1945, with just her sister at her side |
|
my $data = read_file($diaryfile); |
|
|
|
# Clean everything up. (= |
|
# "God is a place; You will wait for the rest of your life." |
|
$data =~ s/\<br \/>//gi; |
|
$data =~ s/\<table>//gi; |
|
$data =~ s/\<\/table//gi; |
|
$data =~ s/\<br \///gi; |
|
$data =~ s/\<tr>\///gi; |
|
$data =~ s/\<\/tr>\///gi; |
|
$data =~ s/<tr>//gi; |
|
$data =~ s/\<\/tr>//gi; |
|
$data =~ s/<td>//gi; |
|
$data =~ s/<\/td>//gi; |
|
$data =~ s/\s\\_//gi; |
|
$data =~ s/\\_\w//gi; |
|
$data =~ s/\w\\_//gi; |
|
$data =~ s/!\\_//gi; |
|
|
|
write_file($diaryfile, $data); |
|
|
|
exit; # all done. |
|
|
|
# read some stuff |
|
sub read_file { |
|
my ($filename) = @_; |
|
|
|
open my $in, '<:encoding(UTF-8)', $filename or die "Could not open '$filename' for reading $!"; |
|
# "In my dreams you're alive and you're crying" |
|
local $/ = undef; |
|
my $all = <$in>; |
|
close $in; |
|
|
|
return $all; |
|
} |
|
|
|
# write some stuff to the file |
|
sub write_file { |
|
my ($filename, $content) = @_; |
|
|
|
open my $out, '>:encoding(UTF-8)', $filename or die "Could not open '$filename' for writing $!"; |
|
# "Rings of flowers around your eyes, |
|
# And I'll love you for the rest of your life when you're ready |
|
|
|
print $out $content; |
|
close $out; |
|
|
|
return; |
|
} |