0x001 前言
前几天看新闻
一程序员大哥由于工作经常忽略女友的消息,最后干脆写了个自动回复的聊天机器人,全天24小时自动回复女友消息😏最后,女朋友和机器人幸福的生活在一起了😏;
新闻标题

作为技术宅的我,怎么可能落后,立马写出相同功能的python程序;
0x002 准备
使用本程序前请安装Python 3.6环境;(百度一下你就知道怎么安装)
使用本程序前请安装Ithat环境或wxpy环境;(安装就是将下面两个pip复制到CMD窗口运行一下)
如果不会安装环境请自行百度pip install Itchat 与 pip install wxpy;
0x003 代码
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
import itchat
bot = Bot(cache_path = True)
my_friend = ensure_one(bot.search('zhaike'))#xxx表示微信昵称
tuling = Tuling(api_key="1234567890")#图灵API
@bot.register(my_friend)
def reply_my_friend(msg):
tuling_reply = tuling.do_reply(msg)
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( cache_path=True)
# 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'zhaike')[0] #xxx表示微信昵称
my_friend.send(get_news()[1][5:]+'---来自一个喜欢你的人!')
print(u"成功!!")
t = Timer(86400, send_news) #360是秒数
t.start()
except:
print(u"失败!!")
if __name__ == "__main__":
send_news()
#print(get_news()[0])
bot.start()
复制代码保存文本文档,把.TXT更改为.py
将你更改的这个文件复制到C盘根目录下;(其他盘也可以,但是相应要更改命令地址;)
用管理员打开CMD命令窗口;
输入:
cd C:/
python 文件名.py
回车即可,然后会有个二维码,你扫码登录一下就可以了呢!如果没有弹窗到C盘根目录下,有个QR.jpg 打开扫码就好;
剩下的我太懒了,但是有点经验的不用说都会,先这样吧!有空更新详细点的教程;

Comments 2 条评论
女朋友呢?聊天呢?这也太懒了8
@St 呜呜呜……我还没有女朋友…..3.3