给最好看的女朋友的每日一句

本文介绍如何使用Python的itchat库自动化发送金山词霸每日一句到指定微信好友,包括安装依赖库、获取每日一句及自动化发送的完整代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先安装itchat,itchat是一个开源的微信个人号接口,可以方便的使用python调用微信

安装itchat和Request

pip install itchat
pip install requests

代码如下:

from __future__ import unicode_literals
from threading import Timer
import requests
import itchat

#在命令行打印微信登陆的二维码
itchat.auto_login(enableCmdQR=2)

#获取金山词霸每日一句,英文和翻译
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()
        users=itchat.search_friends(name='zhangbing')#这里的name是你微信好友的备注,改成你要发送的好友的备注就行了
        userName=users[0]['UserName']
        itchat.send(content,toUserName=userName)
        itchat.send(note,toUserName=userName)
        t = Timer(86400, send_news)#每86400秒(即一天)发送一次
        t.start()
    except:
        #当发送失败时,会给微信文件助手发送fail in send
        itchat.send('fail in send',toUserName='filehelper')
        print('fail in send')


if __name__ == "__main__":
    send_news()

可以把这个放在服务器上,就可以每天给可爱的人呀发送每日一句啦

放一张测试的图

参考链接:https://www.cnblogs.com/syq666/p/8690256.html

itchat文档:https://itchat.readthedocs.io/zh/latest/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值