commit 06ce84e6db72be2bc02e37c9719776e241acca94
parent 7736a9cc2f38502cc149fa7d0e7a26ff1d307a9e
Author: Dan Callaghan <djc@djc.id.au>
Date: Thu, 5 Jun 2008 23:52:59 +1000
extract tags and categories from Wordpress
committer: Dan Callaghan <djc@djc.id.au>
--HG--
extra : convert_revision : be2def25d399265d4b9b6dd03f7793c8e123651b
Diffstat:
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/export_wp.py b/export_wp.py
@@ -4,16 +4,23 @@ import MySQLdb
cn = MySQLdb.connect(host='cruz', user='root', passwd='ELIDED', db='wordpress')
cur = cn.cursor()
-cur.execute('SELECT post_name, post_title, post_date, post_modified, guid, post_content FROM wp_posts WHERE post_status = "publish"')
+cur.execute('SELECT id, post_name, post_title, post_date, post_modified, guid, post_content FROM wp_posts WHERE post_status = %s', ('publish',))
for row in cur.fetchall():
- post_name, post_title, post_date, post_modified, guid, post_content = row
+ id, post_name, post_title, post_date, post_modified, guid, post_content = row
+ subcur = cn.cursor()
+ subcur.execute('SELECT wp_terms.name FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id INNER JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id WHERE taxonomy = %s AND object_id = %s', ('category', id,))
+ categories = [category for category, in subcur.fetchall()]
+ subcur = cn.cursor()
+ subcur.execute('SELECT wp_terms.name FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id INNER JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id WHERE taxonomy = %s AND object_id = %s', ('post_tag', id,))
+ tags = [tag for tag, in subcur.fetchall()]
+
os.mkdir(post_name)
f = open(os.path.join(post_name, 'content.txt'), 'w')
f.write('Title: %s\n' % post_title)
f.write('Publication-date: %s\n' % post_date.strftime('%Y-%m-%d %H:%M:%S'))
f.write('Guid: %s\n' % guid)
- #f.write('Categories: %s\n' % XXX)
- #f.write('Tags: %s\n' % XXX)
+ f.write('Categories: %s\n' % ', '.join(categories))
+ f.write('Tags: %s\n' % ', '.join(tags))
f.write('\n')
f.write(post_content)
del f