import dataset
import codecs
import os
fname=os.path.abspath(__file__)
elmts=fname.split(os.path.sep)
path2=os.path.sep.join(elmts[0:-1])
keysdir=path2+os.path.sep
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
#tablename='gap_searchome'
#tablename='gap_hhh'
tablename='gap_d100'

#db.query('delete from '+tablename)
table=db[tablename]
#fr=codecs.open('hhh/data/searchome.csv','r','utf-16')
#fr=codecs.open('hhh/data/hhh.csv','r','utf-16')
fr=codecs.open('C:\\Users\\jared\\Downloads\\d100.csv','r','utf-16')

lines=fr.readlines()
fr.close()

for l in lines[3:]:
    elmts=l.split('\t')
#    print(elmts)
    print(elmts[0])
    print(elmts[2])
    cnt=0
    try:
        cnt=int(elmts[2])
    except:
        cnt=0
    table.insert({'q':elmts[0],'cnt':cnt})