# make import data
use strict;

my %index;

# reading sitemaps.xml
open(INPUT, "sitemaps.xml") || die "can't open your 'sitemaps.xml'";
local $/ = "</url>";
while (<INPUT>) {
	if (/<loc>http:\/\/.+\/blog-entry-([0-9]+)\.html<\/loc>/) {
		my $num = $1;
		if (/<lastmod>([^\+]+).+<\/lastmod>/) {
			$index{$1} = $num;
		}
	}
}
close (INPUT);

$/ = "\n--------\n";

while (<>) {

	my $date;

	# "03/31/2005 06:16:23" -> "2005-03-31T06:16:23"
	if (/^DATE: ([0-9][0-9])\/([0-9][0-9])\/([0-9][0-9][0-9][0-9]) ([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/m) {
		$date = "$3-$1-$2T$4";
	}

	my $n = $index{$date};
	if ($n == 0) { die "something wrong ! (date:'$date')"; }

	# entry paths
	s{blog-entry-([0-9]+)\.html} {archives/$1}g;
	
	# hostname
	s{blogger323\.blog83\.fc2\.com} {hetarena.com}g;

	# attachments (images)
	s{http://blog-imgs-[0-9]+\.fc2\.com/b/l/o/blogger323/([^"]+)"} {/oldimages/$1"}g;

	# insert ID
	s/^(AUTHOR: .+)$/$1\nID: $n/mg;

	# output
	print;

}
