Shahzad Bhatti Welcome to my ramblings and rants!

March 31, 2007

Moving my Blog from Blojsom to WordPress

Filed under: Computing — admin @ 7:09 pm

Moving my Blog from Blojsom to WordPress

I recently changed my ISP from my old friend Aligen (courtesy of Farrad Ali for providing free access since ’98) to HostMonster. So, instead of running my own Tomcat now I am relying on PHP and Rails. The next thing was how do I move my blogs and preserve the dates. Blojsom was simple file based software, but WordPress uses mysql. So I wrote a simple ruby script to convert it.

The first thing I did was to download dbi from

I then uncompressed it

		tar xzf dbi-0.1.1.tar.gz


cd ~/ruby-dbi

Since, I don’t have root access on my host, I could not install it to the /usr/bin directory. So I created my own ruby directory

mkdir ~/ruby

and then ran config with my own bin directory as

ruby setup.rb config –bin-dir=~/bin –with=dbi,dbd_mysql –rb-dir=~/ruby –so-dir=~/ruby

Next I ran
ruby setup.rb setup

and then

ruby setup.rb install

Now then fun part, following is a ruby script that reads my flat files and inserts them into wordpress database:

 1 #!/usr/bin/ruby
 2 require 'dbi'
 4 #
 5 ### import blogs from old blog directory to wordpress
 6 #
 7 class ImportBlogs
 8   def initialize(webapp_dir)
 9     @webapp_dir = webapp_dir
10   end
12   def delete_all
13     DBI.connect('DBI:Mysql:weblog', 'weblog', '*****') do | dbh |
14'delete from wp_posts where id > 2')
15     end
16   end
18   def add_all
19     files = Dir.glob("#{@webapp_dir}/*").delete_if { |f| }
20     DBI.connect('DBI:Mysql:weblog', 'weblog', '*****') do | dbh |
21       id = 3
22       post_author = 1
23       sql = "insert into wp_posts(post_author, post_date, post_date_gmt, post_content, post_title, post_category, post_excerpt, post_name, post_modified, post_modified_gmt, guid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
24       dbh.prepare(sql) do | sth |
25         files.each do |f|
26           lines = nil
27 , "r") do |file|
28             lines = file.readlines
29           end
30           post_content = lines.join(' ')
31           post_title = lines[0]
32           post_excerpt = post_content.slice(0,255)
33           post_date = post_date_gmt = post_modified = post_modified_gmt =
34           post_category = 3
35           post_name = File.basename(f)
36           guid = "{id}"
37           puts "Adding #{f} mtime #{post_date}"
38           sth.execute(post_author, post_date, post_date_gmt, post_content, post_title, post_category, post_excerpt, post_name, post_modified, post_modified_gmt, guid)
39           id += 1
40         end
41       end
42     end
43   end
44 end
46 ib ='~/webapps/blojsom/computing')
47 ib.delete_all
48 ib.add_all

Finally, I ran it as follows:
ruby -I /usr/lib/ruby/gems/1.8/gems/mysql-2.7 -I /usr/lib/ruby/gems/1.8/gems/mysql-2.7/lib -I ~/ruby -I ~/ruby/DBD -I ~/ruby/dbi -I ~/ruby/DBD/Mysql import_blogs.rb
Voilla, I got everything as expected.

March 29, 2007

About Shahzad Bhatti

Filed under: Uncategorized — admin @ 10:41 pm

Welcome to the my neck of the woods. My name is Shahzad Bhatti and I am living in Seattle area and married with children. For about fifteen years, I have been software developer by day job and a software hacker by night, i.e, after ten hours of day job, I work on personal commercial and open source projects.
I generally distinguish developers into following categories:

So, I consider myself hacker, generalist and tool builder. Like many other
enthusiastics, I chase any new computer technologies and after chasing
OO, Java, Jini, CORBA, and J2EE for many years, I have putting more focus
lately on light-weight J2EE, JXTA, J2ME, aspect-oriented programming, ruby, rails and agile methodologies.

My academic interest includes distributed and parallel programming. I developed
a Java based framework called “JavaNOW” to write parallel applications similar
to Linda and PVM systems. You can find some links to parallel programming
at my bookmarks page, from my page or myspace.

Besides computing, I like to read books on Astronomy, unsolved mysterious,
mathematics, aliens/UFOs and ancient civilizations. In Astronomy, I like
String or Unified theory and hopefully one day it can sort out the
difference between Quantum Mechanics and General theory of relativity.
I love to read ancient
civilizations such as Egyptians, Summerians, Babylonians, etc. There
is a wealth of knowledge that has been lost specially prior to Noah’s
flood. May be we will find a huge library in one of the pyramids one day.
You can checkout some cool sites at
my bookmarks page or from my links section. My link to Ward’s wiki page is and my link to wikipedia is

I also own a small consulting and software development company and spend spare
time writing interesting applications. May be someday I would get to quit my
day job. You can visit
Software Section of my
business website. These products are also available at

Occasionally, I gaze at heavens and stars with my Orion SkyQuest XT8 Dobsonian Reflector

Checkout mosaic or list of a few books that I have been reading lately from Amazon. I generally buy 60-70% of my books from Amazon. Luckily, Amazon has nice feature to download history which makes this list easy to view.

Checkout my blog to find insight into my thoughts.

You can also sign my guest book.
I would love to hear your feedback about this site or you can tell me a little bit about

Thank you for visiting my website.

March 3, 2007

Human face of collateral damage

Filed under: Politics — admin @ 1:19 pm

Human face of collateral damage

The Shock and Awe Gallery

Horrific images from Labanon

Pictures From Qana

Popular Blog Entries

Filed under: Computing — admin @ 1:19 pm

Popular Blog Entries

Powered by WordPress