constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit 089ccc0264bbab059e88ce6f593893f88969c611
parent 4bc57b5fe8bce2e1ca1a98218a4b17b6cee3d6c7
Author: Dan Callaghan <djc@djc.id.au>
Date:   Thu,  5 Jun 2008 23:24:13 +1000

rudimentary Wordpress export, re-arranged entries into their own subdir

committer: Dan Callaghan <djc@djc.id.au>

--HG--
extra : convert_revision : 205bb1233c57dcfa421e7e78d9d9133e5c4be6a0

Diffstat:
Mapp.py | 8+++++---
Mblog.py | 4++--
Aexport_wp.py | 21+++++++++++++++++++++
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/app.py b/app.py
@@ -4,9 +4,11 @@ from colubrid import RegexApplication, HttpResponse, execute
 from colubrid.exceptions import PageNotFound, HttpFound
 from colubrid.server import StaticExports
 
-from blog import BASE_DIR, Entry
+from blog import Entry
 
-template_loader = TemplateLoader(os.path.join(BASE_DIR, 'templates'), auto_reload=True)
+template_loader = TemplateLoader(
+		os.path.join(os.path.dirname(__file__), 'templates'), 
+		auto_reload=True)
 
 class BlogApplication(RegexApplication):
 
@@ -23,7 +25,7 @@ class BlogApplication(RegexApplication):
 		return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
 
 app = BlogApplication
-app = StaticExports(app, {'/static': os.path.join(BASE_DIR, 'static')})
+app = StaticExports(app, {'/static': os.path.join(os.path.dirname(__file__), 'static')})
 
 if __name__ == '__main__':
 	execute(app)
diff --git a/blog.py b/blog.py
@@ -3,7 +3,7 @@ from datetime import datetime
 import markdown
 
 
-BASE_DIR = '.'
+ENTRIES_DIR = os.path.join(os.path.dirname(__file__), 'entries')
 BASE_URL = ''
 
 
@@ -30,7 +30,7 @@ class Entry(object):
 
 	def __init__(self, id):
 		self.id = id
-		self.dir = os.path.join(BASE_DIR, id)
+		self.dir = os.path.join(ENTRIES_DIR, id)
 		self.comments_dir = os.path.join(self.dir, 'comments')
 
 		if not os.path.exists(self.dir):
diff --git a/export_wp.py b/export_wp.py
@@ -0,0 +1,21 @@
+import os, time
+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"')
+for row in cur.fetchall():
+    post_name, post_title, post_date, post_modified, guid, post_content = row
+    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('\n')
+    f.write(post_content)
+    del f
+    os.utime(os.path.join(post_name, 'content.txt'), 
+            (time.mktime(post_modified.timetuple()), time.mktime(post_modified.timetuple())))