# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import MySQLdb
import csv

i = 0
out = []
pnpdb = MySQLdb.connect(host="a2nlmysql13plsk.secureserver.net",  # your host 
                     user="coreypace",       # username
                     passwd="Aud12rey",     # password
                     db="FarmBusiness")   # name of the database
 
# Create a Cursor object to execute queries.
pnpcur = pnpdb.cursor()

file = 'C:/Users/cpace/Documents/markethistory.csv'
with open(file) as csvfile:
    spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
    for row in spamreader:
        pnpcur.execute("""insert into MarketHistory (Crop, Contract, Year, Symbol, Date, Open, High, Low, Close, Vol, OI, PriceIndex, PricePercentile) \
                values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""", (row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13]))
                
#                ('"' + row[1] + '", "' + row[2] + '", "' + row[3] + '", "' + row[4] + '", "' + row[5] + '", "' + row[6] + '", "' + row[7] + '", "' + row[8] + '", "' + row[9] + '", "' + row[10] + '", "' + row[11] + '", "' + row[12] + '", "' + row[13] + '"')
        print(i)
        pnpdb.commit()
        i+=1
pnpdb.close()