-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvotes.py
More file actions
29 lines (24 loc) · 734 Bytes
/
votes.py
File metadata and controls
29 lines (24 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import MySQLdb
from xml.dom import minidom
xmldoc=minidom.parse("Votes.xml")
rowele=xmldoc.getElementsByTagName('row')
db = MySQLdb.connect("localhost","root","PASSWORD","DATABASE")
cursor = db.cursor()
for i in range(len(rowele)):
try :
postid = str(rowele[i].attributes['PostId'].value)
except :
postid = 'NULL'
try :
voteid = str(rowele[i].attributes['VoteTypeId'].value)
except :
voteid = 'NULL'
try :
date = str(rowele[i].attributes['CreationDate'].value)
date = MySQLdb.escape_string(date)
except :
date = 'NULL'
insert_sql = "INSERT INTO `Votes` (`PostId`,`VoteTypeId`,`CreationDate`) VALUES ('%s', '%s', '%s')" %(postid,voteid,date)
print insert_sql
cursor.execute(insert_sql)
db.commit()