Merge branch 'dev' into live
[dylansserver.git] / publish_projects.py
1 #!/usr/bin/python
2
3 PROJECTS_DIRECTORY = '/home/dylan/docs/projects'
4
5 import os
6 import time
7 import MySQLdb as db
8 import ConfigParser
9
10 config = ConfigParser.RawConfigParser()
11 config.read('/etc/dylanstestserver.ini')
12 domain = config.get('database', 'domain')
13 user = config.get('database', 'user')
14 password = config.get('database', 'password').replace('"', '')
15 database = config.get('database', 'database')
16 cursor = db.connect(domain, user, password, database).cursor()
17
18 notes = os.listdir(PROJECTS_DIRECTORY)
19
20 sql = "SELECT title FROM projects"
21 cursor.execute(sql)
22 results = cursor.fetchall()
23 existing_titles = []
24 for row in results:
25 existing_titles.append(row[0])
26
27 for note in notes:
28 if (note[:1] == '.'): continue
29 title = note[:note.index('.')]
30 f = open(os.path.join(PROJECTS_DIRECTORY, note))
31 if title in existing_titles: continue
32 text = f.read()
33 cursor.execute("INSERT INTO projects (title, text)\
34 VALUES (%s, %s)", (title, text))