added script to populate notes disinclined/dl.future/master disinclined/master dl.future/master master
authorDylan Lloyd <dylan@dylansserver.com>
Thu, 7 Mar 2013 05:11:05 +0000 (00:11 -0500)
committerDylan Lloyd <dylan@dylansserver.com>
Thu, 7 Mar 2013 05:11:05 +0000 (00:11 -0500)
populate_notes [new file with mode: 0755]

diff --git a/populate_notes b/populate_notes
new file mode 100755 (executable)
index 0000000..ef2a205
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/env python2
+
+NOTES_DIRECTORY = '/home/dylan/docs/notes'
+
+import os
+import time
+import MySQLdb as db
+import ConfigParser
+
+config = ConfigParser.RawConfigParser()
+config.read('/etc/dylansserver.ini')
+domain = config.get('database', 'domain')
+user = config.get('database', 'user')
+password = config.get('database', 'password').replace('"', '')
+cursor = db.connect(domain, user, password, 'dylansserver').cursor()
+
+notes = os.listdir(NOTES_DIRECTORY)
+
+sql = "SELECT date_posted, url, title, text FROM notes"
+cursor.execute(sql)
+results = cursor.fetchall()
+existing_titles = []
+for row in results:
+    date_posted = row[0]
+    url = row[1]
+    title = row[2]
+    text = row[3]
+    filename = os.path.join(NOTES_DIRECTORY, url + '.html')
+    f = open(filename, 'w')
+    f.write(title + "\n" + date_posted.strftime("%Y/%m/%d %I:%M%p") + "\n" + text)
+    print filename + ' created'