-
Notifications
You must be signed in to change notification settings - Fork 1
/
addRecords.py
103 lines (77 loc) · 2.55 KB
/
addRecords.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python
# -*- coding: utf-8 -*-
import mysql.connector
from mysql.connector import errorcode
from mako.template import Template
from mako.lookup import TemplateLookup
mylookup = TemplateLookup(directories=['.'])
assignmentsTmpl = Template(filename='assignments.tmpl', lookup=mylookup)
assignmentPartTableTmpl = Template(filename='assignmentPartTable.tmpl',
lookup=mylookup)
assignmentAllTableTmpl = Template(filename='assignmentAllTable.tmpl',
lookup=mylookup)
assignmentStartTmpl = Template(filename='assignmentStart.tmpl',
lookup=mylookup)
assignmentEndTmpl = Template(filename='assignmentEnd.tmpl',
lookup=mylookup)
# assignmentTmpl = Template(filename='header.tmpl')
# FooterTmpl = Template(filename='footer.tmpl')
user = 'testing'
password = ''
host = 'dopt-results.cwf0g50wotli.us-east-1.rds.amazonaws.com'
database = 'dopt_results'
cnx = None
cursor = None
try:
cnx = mysql.connector.connect(user=user, password=password,
host=host, database=database)
# print(self.cnx)
cursor = cnx.cursor()
except mysql.connector.Error, err:
# print(self.cursor)
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print 'Something is wrong your username or password'
print err
exit()
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print 'Database does not exists'
print err
exit()
else:
print err
exit()
userIdStart = 123100000
partIds = [
'8zVuNh0L',
'eaOs8z3l',
'pxIsuCQe',
'clCLq0Vb',
'2gHetJOV',
'ASSX0Lq4',
'OXs89Owz',
'AO0FA8y8',
]
add_result_query = 'INSERT INTO ' + database \
+ '.`result` (`ID`, `courseraUserID`, `assignmentID`, `partID`, `quality`, `proof`, `time`) VALUES (NULL, %s, %s, %s, %s, %s, %s)'
add_user_query = 'INSERT INTO ' + database \
+ '.`user` (`userID`, `courseraUserID`, `userName`) VALUES (NULL, %s, %s)'
for i in range(2000, 20001):
userId = userIdStart + i
user_data = (userId, 'nobody_' + str(userId))
# Insert new employee
cursor.execute(add_user_query, user_data)
# user_index = cursor.lastrowid
# cnx.commit()
for pid in partIds:
result_data = (
userId,
4,
pid,
92345678.901 + i,
0,
0.999,
)
# Insert new employee
cursor.execute(add_result_query, result_data)
# user_index = cursor.lastrowid
cnx.commit()