btbytes (owner)

Revisions

  • 427181 Tue Apr 14 08:55:59 -0700 2009
gist: 95246 Download_button fork
public
Public Clone URL: git://gist.github.com/95246.git
Embed All Files: show embed
CMS2Yaki.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/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()