Skip to content

Instantly share code, notes, and snippets.

@btbytes
Created April 14, 2009 15:55
Show Gist options
  • Save btbytes/95246 to your computer and use it in GitHub Desktop.
Save btbytes/95246 to your computer and use it in GitHub Desktop.
#!/Users/pradeep/grok/bin/python
# encoding: utf-8
"""
cms2yaki.py
Created by Pradeep Gowda on 2008-09-22.
Copyright (c) 2008 Pradeep Gowda. All rights reserved.
"""
import sys
import os
import web
import time
import codecs
db = web.database(dbn=os.environ.get('DATABASE_ENGINE', 'postgres'),db='pgowda_pgcom2')
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
fmap = {
'MARKDOWN': 'text/x-markdown',
'RST': 'text/html',
'TEXTILE': 'text/x-textile',
'HTML': 'text/html'
}
def main():
PROJECT_PATH = '/Users/pradeep/pgyaki/tmp'
categories = db.select('categories')
for cat in categories:
dirpath = os.path.join(PROJECT_PATH, cat.slug)
os.mkdir(dirpath)
articles = db.select('articles', where='is_public=True and category_id=$catid',
vars={'catid':cat.id})
for a in articles:
sdpath = os.path.join(dirpath, a.slug)
os.mkdir(sdpath)
fpath = os.path.join(sdpath, 'index.txt')
content = a.content
if a.format == 'RST':
content = a.html
f = codecs.open(fpath, encoding='utf-8', mode='w')
l = u'From: Pradeep Gowda\n'
l += u'Title: %s\n' % (a.title, )
l += u'Date: %s\n' %(a.pub_date)
l += u'Content-Type: %s\n' % (fmap[a.format], )
l += u'X-Index: yes\n'
l += u'X-Cache-Control: max-age=3600\n'
l += u'DBID: %s\n\n' % (a.id, )
f.write(l)
f.write(u'%s'%(content,))
comments = db.select('comments')
f.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment