基本信息
源码名称:python:搜索微信好友并自动发消息示例源码
源码大小:1.18KB
文件格式:.py
开发语言:Python
更新时间:2019-04-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍



# 下载源码就运行,你需要改动几个地方
 
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
 
 
bot = Bot()
 
# linux执行登陆请调用下面的这句
#bot = Bot(console_qr=2,cache_path="botoo.pkl")
 
 
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():
    try:
        content,note = get_news()
         
        # 你朋友的微信名称,不是备注,也不是微信帐号。
        my_friend = bot.friends().search(u'小明')[0]
        my_friend.send(content)
        my_friend.send(note)
        my_friend.send(u"Have a good one!")
        # 每86400秒(1天),发送1次
        t = Timer(86400, send_news)
        t.start()
    except:
         
        # 你的微信名称,不是微信帐号。
         
        my_friend = bot.friends().search('常念')[0]
        my_friend.send(u"今天消息发送失败了")
 
 
if __name__ == "__main__":
    send_news()