1、机器人聊天
import requests
print('你好,我是一枚萌萌哒的机器人!')
while 1:
s = input()
resp = requests.get("http://api.qingyunke.com/api.php", {
'key': 'free',
'appid': 0,
'msg': s
})
resp.encoding = 'utf-8'
resp = resp.json()
print(resp['content'])
2、微信自动聊天
'''
@Time : 2018/5/30 20:48
@Author : Fate
@File : weix.py
'''
import requests
import itchat
KEY = 'ca098ebe818b49df98af997bef29b3b3'
def get_response(msg):
Url = 'http://www.tuling123.com/openapi/api'
data = {
'key': KEY,
'info': msg,
'userid': 'pth-robot',
}
try:
r = requests.post(Url, data=data).json()
return r.get('text')
except:
return
def tuling_reply(msg):
defaultReply = 'I received: ' + msg['Text']
reply = get_response(msg['Text'])
return reply or defaultReply
itchat.auto_login(hotReload=True)
itchat.run()