python 实现微信自动回复和好友签名分析

废话不多说了,代码不多,简单粗暴,我就直接上代码:

1.自动回复

#coding=utf8
import itchat
import  time

# 自动回复
# 封装好的装饰器,当接收到的消息是Text,即文字消息
@itchat.msg_register(Text)
def text_reply(msg):
    # 当消息不是由自己发出的时候
    if not msg[FromUserName] == myUserName:
        # 发送一条提示给文件助手
        itchat.send_msg(u"[%s]收到好友@%s 的信息:%s\n" %
                        (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(msg[CreateTime])),
                         msg[User][NickName],
                         msg[Text]), filehelper)
        # 回复给好友
        return u[自动回复]@%s您好!抱歉 \n我现在有事不在,一会再和您联系。\n已经收到您的的信息:%s\n % (msg[Text])

if __name__ == __main__:
    itchat.auto_login()

    # 获取自己的UserName
    myUserName = itchat.get_friends(update=True)[0]["UserName"]
    itchat.run()

2.好友签名分析

 

# coding:utf-8
import  itchat
import  pandas
import re
import jieba
itchat.login()
friends =itchat.get_friends()
df_friends = pandas.DataFrame(friends)
Signatures = df_friends.Signature
regex1 = re.compile(<span.*?</span>) #匹配表情
regex2 = re.compile(\s{2,})#匹配两个以上占位符。
Signatures = [regex2.sub( ,regex1.sub(‘‘,signature,re.S)) for signature in Signatures] #用一个空格替换表情和多个空格。
Signatures = [signature for signature in Signatures if len(signature)>0] #去除空字符串
text =  .join(Signatures)
wordlist = jieba.cut(text, cut_all=True)
word_freq = {}
for word in wordlist:
    if word in word_freq:
        word_freq[word] += 1
    else:
        word_freq[word] = 1

freq_word = []
for word in word_freq.items():
    freq_word.append((word))
freq_word.sort(key = lambda x: x[1], reverse = True)

for word in freq_word:
    print(word)

 

python 实现微信自动回复和好友签名分析

上一篇:java4android (基本概念)


下一篇:Building Apps for Windows Phone 8.1教程下载地址整理