-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlConnectionTesting.py
44 lines (41 loc) · 1.56 KB
/
sqlConnectionTesting.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
import csv
from configparser import ConfigParser
import mysql.connector
appConfig = ConfigParser()
appConfig.read("App.ini")
host = appConfig.get("CoreContext", "host")
user = appConfig.get("CoreContext", "user")
password = appConfig.get("CoreContext", "password")
database = appConfig.get("CoreContext", "database")
port = appConfig.get("CoreContext", "port")
cnx = mysql.connector.connect(user=user, password=password,
host=host, port=port,
database=database,
ssl_disabled=False)
mycursor = cnx.cursor()
print("Uploading to SQL DB..")
entryNum = 0
multi = 0
percentageDone = 0.00
with open('showdata.csv') as csvfile:
showlistRaw = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in showlistRaw:
if row[0] == "tconst":
continue
query = 'INSERT INTO tvShowsSQLDB (tconst, parentTConst, seasonNumber, episodeNumber, averageRating,epName) values(\'%s\', \'%s\', %s, %s, %s,\' %s\')' % (
row[0], row[1], row[2], row[3], row[4], row[5])
try:
mycursor.execute(query)
entryNum += 1
# Upon the 1000th row, we commit to the SQL Server
if entryNum == 1000:
multi += 1
entryNum = 0
print("Last Entry: ", row[0])
print(multi, "K enteries Uploaded")
cnx.commit()
except KeyError:
print("Error, Unable to add value ", row)
continue
cnx.commit()
print(mycursor.rowcount, "record inserted.")