# pebble-wordpress.py # # BSD License: # # Copyright (c) 2008, Erik Isaksson # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted # provided that the following conditions are met: # # Redistributions of source code must retain the above copyright notice, this list of conditions # and the following disclaimer. # Redistributions in binary form must reproduce the above copyright notice, this list of conditions # and the following disclaimer in the documentation and/or other materials provided with the # distribution. # Neither the name of Erik Isaksson nor the names of its contributors may be used to endorse # or promote products derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # Modify these strings: # Directory where you've unzipped your exported Pebble blog: src_dir = 'C:/Users/User/pebble-export/' # URL to replace ./images/ with (must end with a slash): # (This is where images uploaded to Pebble are located.) img_url = 'http://www.example.com/blog/images/' from Ft.Lib import Uri from Ft.Xml.Xslt import Processor from Ft.Xml.InputSource import DefaultFactory import os import re xsl_uri = Uri.OsPathToUri('pebble-wordpress.xsl') xsl_src = DefaultFactory.fromUri(xsl_uri) processor = Processor.Processor() processor.appendStylesheet(xsl_src) f = open('wordpress-sql.txt', 'w') for root, dirs, files in os.walk(src_dir): for name in files: if re.search('([0-9]+)\.xml$', name) != None: doc_uri = Uri.OsPathToUri(os.path.join(root, name)) doc_src = DefaultFactory.fromUri(doc_uri) m = re.search('(\w*)\.xml$', name) params = {u'postname': unicode(m.groups()[0]), u'imageurl': unicode(img_url)} result = processor.run(doc_src, outputStream=f, topLevelParams=params) f.write('\nUPDATE wp_posts SET comment_count=(SELECT COUNT(*) FROM wp_comments WHERE comment_post_ID=wp_posts.ID AND comment_approved="1");\n'); f.write('\nUPDATE wp_term_taxonomy SET count=(SELECT COUNT(*) FROM wp_posts WHERE EXISTS (SELECT * FROM wp_term_relationships WHERE wp_term_relationships.object_id=wp_posts.ID AND wp_term_relationships.term_taxonomy_id=wp_term_taxonomy.term_taxonomy_id) AND post_status="publish");\n'); f.close()