import pymysql.cursors
import requests

conn = pymysql.connect(host='dev-swh.ga',
                       user='root',
                       password='swhacademy!',
                       db='market',
                       charset='utf8')
try:
    with conn.cursor() as cursor:
        sql = '''
            CREATE TABLE sentimental (
                word_root varchar(255) NOT NULL,
                polarity int(11) NOT NULL
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8
'''
        cursor.execute(sql)

        URL = 'https://raw.githubusercontent.com/park1200656/KnuSentiLex/master/data/SentiWord_info.json'
        response = requests.get(URL)
        data = response.json()
        for b in data:
            sql = 'INSERT INTO sentimental (word_root, polarity) VALUES (%s, %s)'
            cursor.execute(sql, (b['word_root'], b['polarity']))
    conn.commit()
    print(cursor.lastrowid)
finally:
    conn.close()