sed -i s/\"/\'/g projects/* && rm print()s in pub*
[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 cursor = db.connect(domain, user, password, database).cursor()
15
16 notes = os.listdir('projects')
17
18 sql = "SELECT title FROM projects"
19 cursor.execute(sql)
20 results = cursor.fetchall()
21 existing_titles = []
22 for row in results:
23 existing_titles.append(row[0])
24
25 for note in notes:
26 title = note[:note.index('.')]
27 f = open(os.path.join('projects', note))
28 if title in existing_titles: continue
29 text = f.read()
30 cursor.execute("INSERT INTO projects (title, text)\
31 VALUES (%s, %s)", (title, text))