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