Import Textpattern to Jekyll
Obsolete. Here only to prevent link rot.
Created:
A python script to import blog posts from textpattern to Jekyll
Requires: web.py
Update 2023-10-31: copied code from gist to inline. No other changes.
import os
import web
import codecs
= web.database(dbn=os.environ.get('DATABASE_ENGINE', 'mysql'),
db ='textpatterndb', user="root", passwd="BANANA")
dbdef main():
= """SELECT Title, id,
QUERY url_title,
Posted,
Body,
concat(Category1, case when Category2 <> '' then concat(' ', Category2) else '' end) as Categories, \
comments_count
FROM textpattern
WHERE Status = '4' OR
Status = '5';
"""
= db.query(QUERY)
results
for r in results:
= r.Body
content = r.url_title
slug = '-'.join([r.Posted.strftime("%Y-%m-%d"), slug]) + ".textile"
name '/tmp/_posts')
os.makedirs(
= codecs.open('/tmp/_posts/%s' % name, 'w', "utf-8")
f '---\n')
f.write('layout: post\n')
f.write('title: %s\n' % r.Title.replace('/', '-'))
f.write('categories: %s\n' % r.Categories.replace('/', '-'))
f.write('permalink: %s\n' % slug)
f.write('---\n\n')
f.write(
f.write(content)
f.close()
if __name__ == '__main__':
main()