summaryrefslogtreecommitdiffstatshomepage
path: root/wordpress-to-dir.py
diff options
context:
space:
mode:
authorGravatar Andy Wingo2008-02-20 09:24:18 +0100
committerGravatar Andy Wingo2008-02-20 09:24:18 +0100
commit99162ab839adcfd0dbdf583e5bd6fecd3e5882d7 (patch)
treef02f2e12e85c1ad81ca1d6ddf2ceb4411e7cf19c /wordpress-to-dir.py
parentc2580a017d69faf44cefb2652d17f71b7e4301f0 (diff)
downloadtekuti-99162ab839adcfd0dbdf583e5bd6fecd3e5882d7.tar.gz
tekuti-99162ab839adcfd0dbdf583e5bd6fecd3e5882d7.zip
another checkpoint, la la la
Diffstat (limited to 'wordpress-to-dir.py')
-rw-r--r--wordpress-to-dir.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/wordpress-to-dir.py b/wordpress-to-dir.py
new file mode 100644
index 0000000..e92bd80
--- /dev/null
+++ b/wordpress-to-dir.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+
+import sys
+import tempfile
+import MySQLdb as db
+import os
+
+cxn = None
+
+def all_posts():
+ `ID` bigint(20) unsigned NOT NULL auto_increment,
+ `post_author` bigint(20) NOT NULL default '0',
+ `post_date` datetime NOT NULL default '0000-00-00 00:00:00',
+ `post_date_gmt` datetime NOT NULL default '0000-00-00 00:00:00',
+ `post_content` longtext NOT NULL,
+ `post_title` text NOT NULL,
+ `post_category` int(4) NOT NULL default '0',
+ `post_excerpt` text NOT NULL,
+ `post_lat` float default NULL,
+ `post_lon` float default NULL,
+ `post_status` enum('publish','draft','private','static','object','attachment') NOT NULL default 'publish',
+ `comment_status` enum('open','closed','registered_only') NOT NULL default 'open',
+ `ping_status` enum('open','closed') NOT NULL default 'open',
+ `post_password` varchar(7) NOT NULL default '',
+ `post_name` varchar(67) NOT NULL default '',
+ `to_ping` text NOT NULL,
+ `pinged` text NOT NULL,
+ `post_modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `post_modified_gmt` datetime NOT NULL default '0000-00-00 00:00:00',
+ `post_content_filtered` text NOT NULL,
+ `post_parent` bigint(20) NOT NULL default '0',
+ `guid` varchar(85) NOT NULL default '',
+ `menu_order` int(11) NOT NULL default '0',
+ `post_type` varchar(34) NOT NULL default '',
+ `post_mime_type` varchar(34) NOT NULL default '',
+ `comment_count` bigint(20) NOT NULL default '0',
+ PRIMARY KEY (`ID`),
+ KEY `post_date` (`post_date`),
+ KEY `post_date_gmt` (`post_date_gmt`),
+ KEY `post_name` (`post_name`),
+ KEY `post_status` (`post_status`)
+ cur = cxn.cursor()
+ sql = ('select ID, post_author, post_date_gmt, post_content,'
+ ' post_title, post_status, comment_status, post_name,'
+ ' post_modified_gmt, post_content_filtered'
+ ' from wp_posts')
+ cur.execute(sql)
+ while True:
+ row = cur.fetchone()
+ if row:
+ keys = ('id', 'author', 'date', 'content', 'title',
+ 'status', 'comment_status', 'name', 'modified',
+ 'content_filtered')
+ yield dict(zip(keys, row))
+ else:
+ break
+
+def write_post(post):
+ print post['name']
+
+def main(args):
+ global cxn
+ d = tempfile.mkdtemp(prefix='wp2dir')
+ print 'writing dir', d
+ os.chdir(d)
+ _, host, user, passwd, db = args
+ cxn = db.connect(host=host, user=user, passwd=passwd, db=db)
+ for post in all_posts():
+ write_post (post, post_categories (post), post_comments (post))
+
+if __name__ == '__main__':
+ main(sys.argv)