Skip to content

Commit 6d43206

Browse files
authored
Create weibo.py
1 parent 797574b commit 6d43206

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

moumoubaimifan/weibo.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 爬虫命令
2+
# python3 -m weibo_spider
3+
4+
from aip import AipNlp
5+
import csv
6+
import time
7+
import re
8+
9+
APP_ID = 'APP_ID'
10+
API_KEY = 'API_KEY'
11+
SECRET_KEY = 'SECRET_KEY'
12+
13+
client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
14+
15+
16+
file = open("D:\\weibo\\weibo\\宫崎骏漫画全集\\3733371872.csv", "r", encoding="utf-8", errors='ignore')
17+
reader = csv.reader(file)
18+
result = {'good':0,'bed':-1}
19+
hanzi = re.compile('[\u4e00-\u9fa5 0-9??。.,,]')
20+
for item in reader:
21+
time.sleep(1)
22+
a = "".join(hanzi.findall(item[1]))
23+
if len(a.encode()) > 1024:
24+
continue
25+
26+
sent = client.sentimentClassify(a)
27+
28+
items = sent['items'][0]
29+
if items["positive_prob"] > items["negative_prob"]:
30+
result['good'] = result['good'] + 1
31+
else:
32+
result['bed'] = result['bed'] + 1
33+
34+
print('微博内容总共:{} 条,好心情:{},差心情:{}'.format(result['good'] + result['bed'], result['good'], result['bed']))
35+
if(result['good'] > result['bed']):
36+
print('最近女神心情好,建议发出约会要求')
37+
else:
38+
print('最近女神心情非常差,建议吃大餐')

0 commit comments

Comments
 (0)