analysis_message_rank_all.py
842 Bytes
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
import base64
import sys
import pymysql
from konlpy.tag import Twitter
from collections import Counter
conn=pymysql.connect(host='localhost',user='root',password='1234', db='dataextraction', charset='utf8')
def select():
curs=conn.cursor()
sql="select sms.type, sms.address, sms.date, sms.body, contact.name from sms left join contact on sms.address=contact.number;"
curs.execute(sql)
rows=curs.fetchall()
data=""
for row in rows:
data+=row[3]
analysis_keyword(data)
def analysis_keyword(text):
twitter = Twitter()
result = twitter.nouns(text)
count=Counter(result)
tag_count=[]
for n, c in count.most_common(20):
dics={'tag':n, 'count':c}
tag_count.append(dics)
for tag in tag_count:
return_data=tag['tag']+"|"+str(tag['count'])
print(base64.b64encode(return_data.encode('utf-8')))
select()
conn.close()