-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest4.py
48 lines (34 loc) · 1.13 KB
/
test4.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
45
46
47
48
import pymysql
from nltk.corpus import stopwords
conn=pymysql.connect(host='127.0.0.1',user='root', passwd='root',port=8889,db='AlgebraNationWall')
a = conn.cursor()
sql = 'SELECT id , comment_text FROM WallPosts where is_parent_post=1 order by `ts_created` DESC LIMIT 3;'
a.execute(sql)
#countrow = a.execute(sql)
#print ("Number of rows :",countrow)
#data = a.fetchall()
b = conn.cursor()
c = conn.cursor()
try:
for row in a:
stop = set(stopwords.words('english'))
sentence = row[1]
#print [i for i in sentence.lower().split() if i not in stop]
mainid = row[0]
sql2 = 'SELECT comment_text FROM WallPosts where reply_to_post_id='+str(mainid)+';'
b.execute(sql2)
for comment in b:
sentence = sentence + ' ' +comment[0]
threadwords = [i for i in sentence.lower().split() if i not in stop]
sqlInsert = 'INSERT INTO TopicTags (postGroup,threadwords) VALUES (%s,%s);'
#sqlInsert = 'INSERT INTO TopicTags (postGroup,threadwords) VALUES ("'+sentence+'","'+str(threadwords)+'")'
c.executemany(sqlInsert,sentence,str(threadwords))
except Exception as e:
raise
print(e)
else:
pass
finally:
pass
#print (a)
#print(data)