1 itchat已停用
自从微信禁止网页版登陆之后,itchat 库实现的功能也就都不能用了。
CMD>pip install itchat
chardet-3.0.4
idna-2.8
itchat-1.3.10
pypng-0.0.20
pyqrcode-1.2.1
urllib3-1.25.11
更新已经停止在2017年。
Quick Response Code,是由Denso公司于1994年9月研制的一种矩阵二维码符号,它具有一维条码及其它二维条码所具有的信息容量大、可靠性高、可表示汉字及图象多种文字信息、保密防伪性强等优点。
2 免费聊天机器人
2.1 青云客机器人
完全免费,支持功能:天气、翻译、藏头诗、笑话、歌词、计算、域名信息/备案/收录查询、IP查询、手机号码归属、人工智能聊天。
不用注册,不用申请key,拿来就用!
urllib是Python自带的标准库,无需安装,直接可以用。
# -*- coding:utf-8 -*-
import urllib
import requests
def qingyunke(msg):
re = urllib.parse.quote(msg)
url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg={}'.format(re)
html = requests.get(url)
return html.json()["content"]
msg = '我漂亮吗'
print("原话>>", msg)
res = qingyunke(msg)
print("青云客>>", res)
输出
原话>> 我漂亮吗
青云客>> 你很漂亮,可是没有菲菲这么有气质
其中urllib.parse.quote
>>>import urllib.parse
>>>help(urllib.parse.quote)
quote(string,
safe='/',
encoding=None,
errors=None)
例如
quote('abc def') -> 'abc%20def'
Each part of a URL, e.g. the path info, the query, etc., has a
different set of reserved characters that must be quoted.
RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists
the following reserved characters.
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
Each of these characters is reserved in some component of a URL,
but not necessarily in all of them.
By default, the quote function is intended for quoting the path
section of a URL. Thus, it will not encode '/'. This character
is reserved, but in typical usage the quote function is being
called on a path where the existing slash characters are used as
reserved characters.
string and safe may be either str or bytes objects. encoding and errors
must not be specified if string is a bytes object.
The optional encoding and errors parameters specify how to deal with
non-ASCII characters, as accepted by the str.encode method.
By default, encoding='utf-8' (characters are encoded with UTF-8), and
errors='strict' (unsupported characters raise a UnicodeEncodeError).
2.2 图灵机器人
图灵机器人
网址http://www.tuling123.com
tuling_key: ‘98f95153fb5c4684a5602b909949ba61’
#建议使用自己的图灵机器人API Key
# -*- coding:utf-8 -*-
import urllib
import requests
import json
def tuling(msg):
api_key = "98f95153fb5c4684a5602b909949ba61"
url = 'http://openapi.tuling123.com/openapi/api/v2'
data = {"perception": {"inputText": {"text": msg}},
"userInfo": {"apiKey": api_key, "userId": "1"}}
datas = json.dumps(data)
html = requests.post(url, datas).json()
if html['intent']['code'] == 4003:
print("次数用完")
return None
return html['results'][0]['values']['text']
msg = '我好看吗'
print("原话>>", msg)
res = tuling(msg)
print("图灵>>", res)
输出
原话>> 我好看吗
图灵>> 我看不到,声音好听,应该也很漂亮吧。