github仓库:youfou/wxpygithub.com
文档地址:机器人对象 - wxpy 0.3.9.8 文档wxpy.readthedocs.io
简介:
wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展。
一、安装
pip install wxpy
二、简单介绍
# 导入模块
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot()
# 搜索名称含有 "老范" 的男性上海好友
my_friend = bot.friends().search('老范', sex=MALE, city="上海")[0]
三、完整代码
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
bot = None
def get_news():
#获取一个连接中的内容
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
print(r.json())
contents = r.json()['content']
translation = r.json()['translation']
return contents, translation
def login_wechat():
global bot
bot = Bot() # window
# bot = Bot(console_qr=2,cache_path="botoo.pkl")#linux环境上使用
def send_news():
if bot == None:
login_wechat()
try:
my_friend = bot.friends().search(u'老范')[0] # 老范 表示微信昵称
my_friend.send(get_news()[0])
my_friend.send(get_news()[1][5:])
my_friend.send(u"咦?我是自动人!!")
t = Timer(5, send_news) #5是秒数:5秒发送一次
t.start()
except:
print(u"失败!")
if __name__ == "__main__":
send_news()
# print(get_news()[0])
效果
番外:
可以把秒数改大一点。每天给妹子发一条你想表达的话,嘤嘤嘤。。。。