#!/usr/bin/env python
#-*- coding:utf-8 -*- @Author : wujf @Time:2018/8/21 15:59
# 自动发送消息
from threading import Timer
from wxpy import *
import requests
import urllib2,re,urllib,requests
#bot = Bot(console_qr=2,cache_path='botoo.pk1) #把consol_qr=2去掉,二维码是当做图片弹出来,否则则是以像素的方式打印出来,后面的参数是热登录,
bot = Bot(cache_path=False) # 连接微信,会出现一个登陆微信的二维码
#bot.self.send(u'测试') # 给自己发送消息 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:
my_friend = bot.friends().search(u'邹唯')[0]
my_friend.send(u'今天又到了我给你发问候的时候,嘻嘻嘻\n')
my_friend.send(get_news()[0])
my_friend.send(get_news()[1][13:])
my_friend.send(u'晚安')
# t = Timer(4, send_news) # 这里是一天发送一次,86400s = 24h
# t.start()
except:
my_friend = bot.friends().search(u'风吹过的街道')[0] # 这里是你的微信昵称 (加上u的作用是对后面的字符串进行unicode编码。unicode是书写国际文本的标准方法)
my_friend.send(u'您的消息发送失败了') if __name__ == '__main__':
send_news() bot.join() 最后利用linux的定时任务实现定时

python实现定时发送消息-LMLPHP

04-26 16:09
查看更多