1.Python——给你最爱的心灵鸡汤

1.安装wxpy requests

sudo pip install requests
sudo pip install wxpy

1.2 wxpy 登陆

 wxpy 使用起来非常简单,我们只需要创建一个bot 对象,程序运行后,会弹出二维码,扫描二维码后显示登陆成功。

 下述代码在登陆完成后,会向我们的文件传输助手发送一个“hello world!”。(每个程序都需要一个hello world)

from wxpy import *

bot = Bot()
bot.file_helper.send( 'hello world!' )

print ( "end" )


1.3 你的鸡汤


from __future__ import unicode_literals
import requests
import itchat
import time

def get_news ():
url = "http://open.iciba.com/dsapi"
r = requests.get(url)
contents = r.json()[ 'content' ]
translation = r.json()[ 'translation' ]
return contents, translation

def send_news ():
try :
# 登陆你的微信账号,会弹出网页二维码,扫描即可
itchat.auto_login( hotReload = True )
# 获取你对应的好友备注,这里的小明我只是举个例子
# 改成你最心爱的人的名字。
my_friend = itchat.search_friends( name = u '小明' )
# 获取对应名称的一串数字
XiaoMing = my_friend[ 0 ][ "UserName" ]
# 获取金山字典的内容
message1 = str (get_news()[ 0 ])
content = str (get_news()[ 1 ][ 17 :])
message2 = str (content)
message3 = "来自你最爱的人"
# 发送消息
itchat.send(message1, toUserName = XiaoMing)
itchat.send(message2, toUserName = XiaoMing)
itchat.send(message3, toUserName = XiaoMing)
# 每86400秒(1天),发送1次,
# 不用linux的定时任务是因为每次登陆都需要扫描二维码登陆,
# 很麻烦的一件事,就让他一直挂着吧
# t = time(86400, send_news())
# t.start()
except :
message4 = u "今天最爱你的人出现了 bug /(ㄒoㄒ)/~~"
itchat.send(message4, toUserName = XiaoMing)

def main ():
send_news()

if __name__ == '__main__' :
main()




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值