tdiary to fdus converter

今度はtdiary形式を変換するスクリプトのメモ。日時の抽出とファイル分割まで出来れば後は同じ生HTMLなのでそのまま使える。

#!/usr/bin/perl

$dbg = 0;

for (<*.td2>){
    if($dbg){ print "$_\n";}

    $name = $oname = $_;
    $name =~ s/\.td2$//;

    open(FILE,$oname);

    $flg_title = 0;

    mkdir($name);

    while(<FILE>){

	$line = $_;
	
	next if(/^TDIARY/);

	if(/^Date: ([0-9]{8})/){
	    $date = $1;
	    $out_line = "";
	    next;
	}elsif(/^Title: (.+)/){
	    $title = $1;
	    next;
	}elsif(/^Last-Modified/){
	    next;
	}elsif(/^Visible/){
	    next;
	}elsif(/^Format/){
	    next;
	}elsif(/^\./){

	    # Output File
	    $filename = $date . ".hd";
	    open(FILE2,">$name/$filename");
	    print FILE2 $out_line;
	    close(FILE2);

	    next;
	}
	
	if(/^$/){
	    if($flg_title){
		if($dbg){print "</p>\n";}
		$out_line .= sprintf "</p>\n";
		$flg_title = 0;
	    }
	    next;
	}

	if(!$flg_title){
	    if($dbg){
		print "::: $line";
		print "<p>\n";
		 }
	    $out_line .= sprintf "::: $line";
	    $out_line .= sprintf "<p>\n";
	    
	    $flg_title = 1;
	}else{
	    if($dbg){print "$line";}
	    $out_line .= sprintf "$line";
	}

    }

    close(FILE);

    #exit;

}


This is a converter from tdiary to fdus format. It extracts date and splits to file by a day. The format of the main contents is a raw HTML so we can use the format without modified.