-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmathsread.py
More file actions
36 lines (34 loc) · 1.02 KB
/
mathsread.py
File metadata and controls
36 lines (34 loc) · 1.02 KB
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
import json
import mysql.connector
from mysql.connector import errorcode
try:
cnx = mysql.connector.connect(user='meer', password='kat',
host='localhost',charset='utf8',
database='meerkat4s')
csr = cnx.cursor()
query = (
"INSERT INTO course "
"(version,ects,name,semester)"
"VALUES (%s,%s,%s,%s)")
json_data=open("courses_names").read()
jdata = json.loads(json_data)
for k in range (0, len(jdata['unchosenCourses'])):
course_name = jdata['unchosenCourses'][k][1]
semester = jdata['unchosenCourses'][k][3]
print (course_name)
data = (1,1,course_name,semester)
try:
csr.execute(query,data)
print ('hey')
except Exception, e:
print (str(e))
cnx.commit()
csr.close()
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exists")
else:
print(err)
cnx.close()