raw extraction of data from google blogger to wordpress

This is a small script I wrote to extract all posts from my blogger which was in the form a xml or aton feed and insert into a wordpress database.
import feedparser
import re
d = feedparser.parse(“C:\Python25\programs\blog.xml”)
count = len(d[‘entries’])
loopVar = 0
p = re.compile(r'[‘”]’)
mainInsertString = “INSERT INTO `wp_posts` (`ID`, `post_author`,”
s2 = “`post_date`, `post_date_gmt`, `post_content`, `post_title`,”
s3 = “`post_category`, `post_excerpt`, `post_status`, `comment_status`,”
s4 = “`ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`,”
s5 = “`post_modified`, `post_modified_gmt`, `post_content_filtered`,”
s6 = “`post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`,”
s7 = “`comment_count`) VALUES”
finalInsertString1 = mainInsertString + s2 + s3 + s4 + s5 + s6 + s7
print finalInsertString1
blogID = 3300
finalDBString = “”
finalDBString = finalInsertString1
dbString2 = “, 1, ‘2009-06-17 06:11:54’, ‘2009-06-17 06:11:54’,”
dbString3 = “‘, 0, ”, ‘publish’, ‘open’, ‘open’, ”, ‘palm-pre-and-web-os’, ”,”
dbString4 = ” ”, ‘2009-06-17 21:13:18’, ‘2009-06-17 21:13:18’, ”, 0, ”
dbString5 = “‘http://kmdarshan.com/wordpress/?p=”
dbString6 = “‘, 0, ‘post’, ”, 0),”
f = open(‘C:/Python25/programs/sqlfile.txt’, ‘w+’)
f.write(finalInsertString1)
encoding = “ascii”
loopString = “”
for loopVar in range(48, count):
blogTitle = d.entries[loopVar].title
e = d.entries[loopVar]
data = e.content[0].value
blogContent = p.sub(”, data)
loopString = “(“+ str(blogID) + dbString2 +”‘”+ blogContent + “‘,” + “‘” + blogTitle + dbString3 + dbString4 + dbString5 + str(blogID) + dbString6
f.write(loopString.encode(encoding,”ignore”))
blogID = blogID + 1
loopString = “”
I did this at first by rreading through the XML, taking out all the apostrophe’s so that we dont get any errors while inserting into a the sql table. Also stored them into a file for future use. Not sure why I did this, ahh..mostly the imported on my wordpress was giving me some silly errors and not importing any of my posts.

In

Leave a Reply

Your email address will not be published. Required fields are marked *