第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > python定时发送信息_python实现定时发送消息

python定时发送信息_python实现定时发送消息

时间:2021-11-25 06:41:33

相关推荐

python定时发送信息_python实现定时发送消息

#!/usr/bin/env python

#-*- coding:utf-8 -*- @Author : wujf @Time:/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 = "/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的定时任务实现定时

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。