今天来给大家分享一个撩妹技巧,利用 python 每天给你最心爱的人,发送微信消息,说声晚安。
废话不多说,源代码奉上
def get_news(): ... url = "http://open.iciba.com/dsapi" ... r = request.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'Alice') ... Alice = my_friend[0]["UserName"] ... message1 = str(get_news()[0]) ... content = str(get_news()[1][17:]) ... message2 = str(content) ... message3 = "来自爱你得人" ... itchat.send(message1,toUserName=Alice) ... itchat.send(message2,toUserName=Alice) ... itchat.send(message3,toUserName=Alice) ... t= time(86400,send_news()) ... t.start() ... except: ... message4 = u"今天最爱你得人出现啦 bug /(ToT)/~~" ... itchat.send(message4,toUserName=Alice)
最后只要调用一下sendnews方法,然后保证后台运行,微信就会每天给你心爱得人发送消息了
忘记说了,还要引用几个包
import request
import itchat
import time