每个工作日早上7点30分,给亲爱的她发一条天气预报吧。
图灵机器人可以回复天气,所以,只需要向图灵机器人发送请求,
“广州天气”,再把它的回复转发给她,就好了。
再次使用itchat这个插件。
找到她的微信username很简单。
itchat.search_friend('xxx')[0]['UserName']
通过备注remark_name去找就好了。
现在我向微信群里发消息。
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 8 15:57:41 2017
@author: qcy
"""
import datetime
import requests
import itchat
KEY = 'xxxxxxxxxxxxxxxx' # 这里填拿到的key
def get_response(msg):
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key' : KEY,
'info' : msg,
'userid' : 'wechat-robot',
}
try:
r = requests.post(apiUrl, data=data).json()
return r.get('text')
except:
return
import time
def tuling_reply(addr):
weather_reply = """[Weather Forcast]
--------------
"""+get_response(addr+'天气')
print(weather_reply)
username = itchat.search_chatrooms(name='一根藤上几朵花')[0]['UserName']
# user=itchat.search_friends(name='小Too!!') #输入她的备注
# username=user[0]['UserName']
itchat.send(weather_reply,
toUserName=username)
itchat.auto_login(hotReload=True)
#输入发送天气地点
addr_list = ['筠连','重庆','秦皇岛','上海','成都','宜宾']
while 1:
now = datetime.datetime.now()
now_str = now.strftime('%Y/%m/%d %H:%M:%S')[11:]
print('\r{}'.format(now_str), end='')
if now_str in ['07:30:00','22:00:00']: # 发送
for addr in addr_list:
tuling_reply(addr)
time.sleep(1)
1. 并不知道会不会掉线……
2. 并没有判断是否为工作日……