Python操作微信群发消息检测僵尸粉

"""
使用流程:
扫码登录微信网页版 https://wx.qq.com/ 若登录成功,则功能可使用,否则不可用
"""

import time
from threading import Timer

import requests
from wxpy import *

bot = Bot()  # 连接微信,会出现一个登陆微信的二维码


def get_news():
    """获取金山词霸每日一句"""
    url = 'http://open.iciba.com/dsapi'
    r = requests.get(url)
    content = r.json()['content']
    note = r.json()['note']
    return content, note


def send_news():
    """
    指定微信昵称发
    :return:
    """
    try:
        contents = get_news()
        my_friend = bot.friends().search(u'珊')[0]  # 这里是你微信好友的昵称
        my_friend.send(contents[0])
        my_friend.send(contents[1])
        my_friend.send('好久不见,十分想念')
        t = Timer(86400, send_news)  # 这里是一天发送一次,86400s = 24h
        t.start()
    except Exception as e:
        print('发送失败,异常信息:', e)


def send_all_news():
    """
    群发测试好友是否删除或拉黑你
    :return:
    """
    friends = bot.friends()
    for f in friends:
        try:
            f.send('群发检测僵尸好友')
            time.sleep(1)
        except Exception as e:
            print(f.name, f.nick_name, '发送失败,异常信息:', e)


if __name__ == '__main__':
    # send_news()
    send_all_news()

猜你喜欢

转载自blog.csdn.net/zhu6201976/article/details/105316624