Skip to content

Commit 563aaef

Browse files
committed
微信机器人
1 parent 97bfb65 commit 563aaef

9 files changed

Lines changed: 92 additions & 2 deletions

File tree

PythonDemo/.spyproject/workspace.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ save_non_project_files = False
66

77
[main]
88
version = 0.1.0
9-
recent_files = ['E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4JokeToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYunToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\saveToExcel\\xlwtDemo.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\saveToExcel\\xwltDemo2.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYunToExcel2.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4quickstart.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4Meizitu.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\urllib.requestDemo1.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixin.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinItchat.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchat.py']
9+
recent_files = ['E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4JokeToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYunToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\saveToExcel\\xlwtDemo.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\saveToExcel\\xwltDemo2.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYunToExcel2.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4quickstart.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4Meizitu.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\urllib.requestDemo1.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixin.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinItchatSexAs.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchatRobotGroup.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchatRobotSingle.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYun.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\qqbotRobot.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinQianming.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\numpy\\arrayboolean.py', 'D:\\Anaconda3\\lib\\site-packages\\matplotlib\\pyplot.py']
1010

PythonDemo/spider/bs4WangYiYunToExcel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"""
33
Created on Tue Mar 13 15:11:32 2018
44
5-
@author: Administrator
5+
@author: Snailclimb
6+
@description 爬取网易云音乐歌单(这里只爬取了一页)
67
"""
78

89
from bs4 import BeautifulSoup

PythonDemo/spider/itchat.pkl

-1.24 KB
Binary file not shown.

PythonDemo/spider/qqbotRobot.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Mar 13 20:49:43 2018
4+
5+
@author: Administrator
6+
"""
7+
8+
from qqbot import QQBot
9+
10+
class MyQQBot(QQBot):
11+
def onPollComplete(self, msgType, from_uin, buddy_uin, message):
12+
if message == '-hello':
13+
self.send(msgType, from_uin, '你好,我是QQ机器人')
14+
elif message == '-stop':
15+
self.stopped = True
16+
self.send(msgType, from_uin, 'QQ机器人已关闭')
17+
18+
myqqbot = MyQQBot()
19+
myqqbot.Login()
20+
myqqbot.PollForever()

PythonDemo/spider/weixin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Created on Tue Mar 13 17:01:33 2018
44
55
@author: Administrator
6+
@description 查询微信好友
67
"""
78

89
#!/usr/bin/env python
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Created on Tue Mar 13 17:09:26 2018
44
55
@author: Administrator
6+
@description 微信好友性别比例
67
"""
78

89
import itchat
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Mar 13 21:34:29 2018
4+
5+
@author: Administrator
6+
"""
7+
import re,jieba,itchat
8+
import numpy as np
9+
from PIL import Image
10+
from snownlp import SnowNLP
11+
from wordcloud import WordCloud
12+
import matplotlib.pyplot as plt
13+
itchat.auto_login(hotReload=True)
14+
friends = itchat.get_friends(update=True)
15+
def analyseSignature(friends):
16+
signatures = ''
17+
emotions = []
18+
pattern = re.compile("1f\d.+")
19+
for friend in friends:
20+
signature = friend['Signature']
21+
if(signature != None):
22+
signature = signature.strip().replace('span', '').replace('class', '').replace('emoji', '')
23+
signature = re.sub(r'1f(\d.+)','',signature)
24+
if(len(signature)>0):
25+
nlp = SnowNLP(signature)
26+
emotions.append(nlp.sentiments)
27+
signatures += ' '.join(jieba.analyse.extract_tags(signature,5))
28+
with open('signatures.txt','wt',encoding='utf-8') as file:
29+
file.write(signatures)
30+
31+
# Sinature WordCloud
32+
back_coloring = np.array(Image.open('flower.jpg'))
33+
wordcloud = WordCloud(
34+
font_path='simfang.ttf',
35+
background_color="white",
36+
max_words=1200,
37+
mask=back_coloring,
38+
max_font_size=75,
39+
random_state=45,
40+
width=960,
41+
height=720,
42+
margin=15
43+
)
44+
45+
wordcloud.generate(signatures)
46+
plt.imshow(wordcloud)
47+
plt.axis("off")
48+
plt.show()
49+
wordcloud.to_file('signatures.jpg')
50+
51+
# Signature Emotional Judgment
52+
count_good = len(list(filter(lambda x:x>0.66,emotions)))
53+
count_normal = len(list(filter(lambda x:x>=0.33 and x<=0.66,emotions)))
54+
count_bad = len(list(filter(lambda x:x<0.33,emotions)))
55+
labels = [u'负面消极',u'中性',u'正面积极']
56+
values = (count_bad,count_normal,count_good)
57+
plt.rcParams['font.sans-serif'] = ['simHei']
58+
plt.rcParams['axes.unicode_minus'] = False
59+
plt.xlabel(u'情感判断')
60+
plt.ylabel(u'频数')
61+
plt.xticks(range(3),labels)
62+
plt.legend(loc='upper right',)
63+
plt.bar(range(3), values, color = 'rgb')
64+
plt.title(u'%s的微信好友签名信息情感分析' % friends[0]['NickName'])
65+
plt.show()
66+
analyseSignature(friends)

PythonDemo/spider/weixinchatSingle.py renamed to PythonDemo/spider/weixinchatRobotSingle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Created on Tue Mar 13 19:09:05 2018
44
55
@author: Administrator
6+
@description使用图灵机器人自动与指定好友聊天
67
"""
78

89
from wxpy import Bot,Tuling,embed,ensure_one

0 commit comments

Comments
 (0)