1. 代码
先安装python包 wxpy.
pip install wxpy
根据 wxpy
包的二维码使用网页版方式登录,然后根据设定的时间进行发送,否则等待。
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
import time
import datetime
from datetime import timedelta
# 从缓存中获取登录信息,刚登陆过,无需一直登陆
bot = Bot(cache_path=True)
def send_message(hour = 11, min = 11):
# 你朋友的备注微信名称。
friends = bot.friends().search(u'我')
print(friends)
assert(len(friends) == 1)
my_friend = friends[0]
t = datetime.datetime.utcnow() + timedelta(hours=8)
future = datetime.datetime(t.year,t.month,t.day,hour,min)
if t.hour >= hour:
future += datetime.timedelta(days=1)
time.sleep((future-t).seconds)
# 发生信息
my_friend.send(u"我将披星戴月,奔向理想和你!")
print('done')
if __name__ == "__main__":
send_message(hour=11, min=11)