|
@@ -0,0 +1,28 @@
|
|
1
|
+import pymysql.cursors
|
|
2
|
+import requests
|
|
3
|
+
|
|
4
|
+conn = pymysql.connect(host='dev-swh.ga',
|
|
5
|
+ user='root',
|
|
6
|
+ password='swhacademy!',
|
|
7
|
+ db='market',
|
|
8
|
+ charset='utf8')
|
|
9
|
+try:
|
|
10
|
+ with conn.cursor() as cursor:
|
|
11
|
+ sql = '''
|
|
12
|
+ CREATE TABLE sentimental (
|
|
13
|
+ word_root varchar(255) NOT NULL,
|
|
14
|
+ polarity int(11) NOT NULL
|
|
15
|
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
|
16
|
+'''
|
|
17
|
+ cursor.execute(sql)
|
|
18
|
+
|
|
19
|
+ URL = 'https://raw.githubusercontent.com/park1200656/KnuSentiLex/master/data/SentiWord_info.json'
|
|
20
|
+ response = requests.get(URL)
|
|
21
|
+ data = response.json()
|
|
22
|
+ for b in data:
|
|
23
|
+ sql = 'INSERT INTO sentimental (word_root, polarity) VALUES (%s, %s)'
|
|
24
|
+ cursor.execute(sql, (b['word_root'], b['polarity']))
|
|
25
|
+ conn.commit()
|
|
26
|
+ print(cursor.lastrowid)
|
|
27
|
+finally:
|
|
28
|
+ conn.close()
|