One Unified Global Perspective
Communications with a Global Perspective
Home
Intro
Contact Us
Voice over IP
PBX Solutions
Services
Support
Glossary
Open Source
Blog
Forum

WebMail





2007 May 07 - Mon

Importing a Blosxom Blog into Movable Type

I have my Blosxom based blog organized by category directories rather than by date. I've written a Perl script to take this collection of articles and transform them into a MovableType import file. My content files have a .txt extension. You'll need to change the match string if your extension is different from mine.

To run, there is a variable called dir which you seed with a starting directory. The program then scans that directory and further sub-directories looking for files with the designated suffix. It then uses the first line of a found file for the title. The third and subsequent lines are used for the content.

I've found that after importing, I'm not able to see the body in Movable Type's content editor. How weird... Well, it does show up when you customize the display of the page. It shows up in the extended entry text.

2007/06/12: David Graff suggested an additional print statement before the body block. I havn't tried it, but I hope it works to remedy the missing body bit.

Here is the script:

#!/usr/bin/perl

use strict;
#use File::stat;
use Fcntl ':mode';

my $author = 'ray';
my $ext = '.txt';

my @dirs;
my $dir = '/var/www/html/blog';
push( @dirs, $dir );

while ( $dir = pop( @dirs) ) {
  chdir( $dir );
  opendir( DIR, $dir );
#  print( "$dir\n" );
  foreach my $file ( readdir( DIR) ) {
    if ( $file =~ /.txt$/ ) {
      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
                                                localtime((stat($file))[9]);
     $mon+=1;
     $year+=1900;
     $mon = substr( '0' . $mon, -2 ,2 );
     $mday = substr( '0' . $mday, -2, 2 );
     $hour = substr( '0' . $hour, -2, 2 );
     $min  = substr( '0' . $min, -2, 2 );
     $sec  = substr( '0' . $sec, -2, 2 );
     my $date = "$mon/$mday/$year $hour:$min:$sec";
#     print( "  $file: $date\n");

     open( FILE, '<' . $file );
     my $title = <FILE>;
     chomp( $title );

     my $body;
     my $extbody;
     my $line;
     my $summary = 1;
     while ( $line = <FILE> ) {
       if ( $summary ) {
         $body .= $line;
         if ( length( $line ) < 2 ) {
           $summary = 0;
           }
         }
       $extbody .= $line;
       }

     close( FILE );

     $dir =~ /\/([^\/]+$)/;
     my $category = $1;

     print( "AUTHOR: $author\n" );
     print( "TITLE:  $title\n" );
     print( "DATE: $date\n" );
     print( "PRIMARY CATEGORY: $category\n" );
     print( "STATUS: publish\n" );
#     print( "ALLOW COMMENTS: 1\n" );
#     print( "ALLOW PINGS: 1\n" );
     print("-----\n"); # 2007/06/12 insertion by David Graff
     print( "BODY:\n" . $body . "\n-----\n" );
     print( "EXTENDED BODY:\n" . $extbody . "\n-----\n" );
     print( "--------\n" );
     }

    my $mode = (stat($file))[2];
    if ( S_ISDIR( $mode ) ) {
      if ( '.' ne $file && '..' ne $file ) {
        push( @dirs, $dir . '/' . $file );
        }
      }
    }
  closedir( DIR );
  }


2007 May 06 - Sun

Movable Type Links

Here are some links to various pages in Movable Type that look useful:


I Hate PHP on a database call.

I think this is the second time I've been caught on this. And I should have recalled the second time around to check this.

I'm working through the process of installing and playing with Movable Type. It went quite well. Configuration and maintenance and adding content worked well. Well, up until I decided to enable Dynamic Content generation. Then I found out Movable Type has two faces, a Perl one and a PHP one.

To handle dynamic content, they do an Apache redirect/rewrite through a default php script, one that does a database call. And in order to do the databae call, it opens a connection to the database.

I'm testing with PostgreSQL. My Debian install didn't have, by default, the php4-pgsql package. If it isn't installed, PHP simply aborts somewhere in the code, quietly. How silly. No errors, no messages, no nothing.

So after untold 'echo()' statements later, I tracked it down to a call in the ezsql implementation. Finally the light bulb went on over my head. The fix:

apt-get install php4-pgsql

I'm wondering if there is a way to test for this package, so I don't forget this again.

I probably didn't clue into this before because the main Movable Type scripts are in Perl and use the database connections there. I made the, obviously incorrect assumption, that the PHP scripts were involved and already knew about the database driver. Well, I was incorrect on that one.



Blog Content ©2008
Ray Burkholder
All Rights Reserved
ray@oneunified.net
(441) 505 7293
Available for Contract Work
Resume

RSS: Click to see the XML version of this web page.

View Ray 
Burkholder's profile on LinkedIn
technorati
Add to Technorati Favorites



August
Su Mo Tu We Th Fr Sa
         
29 30
31            


Main Links:
Monitoring Server
SSH Tools
QuantDeveloper Code

Special Links:
Frink

Blog Links:
Sergey Solyanik
Marc Andreessen
HotGigs
Micro Persuasion
... Reasonable ...
Chris Donnan
BeyondVC
lifehacker
Trader Mike
Ticker Sense
HeadRush
TraderFeed
Stock Bandit
The Daily WTF
Guy Kawaski
J. Brant Arseneau
Steve Pavlina
Matt Cutts
Kevin Scaldeferri
Joel On Software
Quant Recruiter
Blosxom User Group
Wesner Moise
Julian Dunn
Steve Yegge

2008
Months
AugSep
Oct Nov Dec




Mason HQ

Disclaimer: This site may include market analysis. All ideas, opinions, and/or forecasts, expressed or implied herein, are for informational purposes only and should not be construed as a recommendation to invest, trade, and/or speculate in the markets. Any investments, trades, and/or speculations made in light of the ideas, opinions, and/or forecasts, expressed or implied herein, are committed at your own risk, financial or otherwise.