Releases: littlecodersh/ItChat
Releases · littlecodersh/ItChat
修复synccheck中的错误
修复synccheck中BadStatusLine及503导致的错误。
synccheck会返回一些例如这样的值:
6f:00:0a:14:d0:9e:f7:90:f3:8d:32:ac:c2:81:aa:c8:d3:aa:bb:0a:14:d0:9e:f7:90:f3:8d:32:ac:c2:81:aa:c8:d3
6f:00:8a:9c:09:74:e4:d8:e0:14:bf:96:3a:56:a0:64:1b:cc:dd:8a:9c:09:74:e4:d8:e0:14:bf:96:3a:56:a0:64:1b
涵义还没有头绪。
v1.3.7: Add message revoke (#370)
增加了消息撤回方法,示例如下:
import itchat
itchat.auto_login(True)
user = itchat.search_friends(nickName='LittleCoder')[0]
r = user.send('hi')
msgId = r['MsgID']
r = itchat.revoke(msgId, user.userName)
itchat.run()
修复循环引用
如果两个类互相引用将导致无法被正常回收,所以采取这种形式:
from weakref import ref
class D(object):
def __init__(self, name):
self.name = name
def __del__(self):
print('[deleted]: %s' % self.name)
class T(D):
@property
def pointer(self):
return getattr(self, '_pointer', lambda: None)()
@pointer.setter
def pointer(self, value):
self._pointer = ref(value)
def fn():
t, d = T('t'), D('d')
t.pointer, d.pointer = d, t
if __name__ == '__main__':
fn()
print('end')
在itchat中主要解决这样两个问题:
你需要对照该版本和前版本的结果比较差别。
from weakref import ref
from itchat.storage import templates
def fn():
chatroom = templates.Chatroom()
chatroom.memberList.append({})
m = chatroom.memberList[0]
return ref(m), ref(chatroom)
if __name__ == '__main__':
a, b = fn()
print(a(), b())
from weakref import ref
from itchat import Core
def fn():
r = Core()
return ref(r)
r = fn()
print(r())
1.3.0版本更新
主要更改
- 更新用户、群、公众号的oop操作
- 在注册方法的返回值中增加User键值,存放发送者的类
- 将注册方法的返回值改为可以通过__getattr__访问
- 另,所有新操作不影响旧的字典的使用方式
oop操作
import itchat
user = itchat.get_friends()[0]
user.send('hi')
同样,群和公众号也是这样访问。
注册方法返回值增加User
import itchat
@itchat.msg_register(itchat.content.TEXT)
def _(msg):
msg['User'].send('hi')
itchat.auto_login(True)
itchat.run()
返回值通过__getattr__访问
import itchat
@itchat.msg_register(itchat.content.TEXT)
def _(msg):
msg.user.send('hi')
itchat.auto_login(True)
itchat.run()
发送文件类
import itchat
itchat.auto_login(True)
with open('t.pdf', 'rb') as f:
r = itchat.send_file('test.pdf', 'filehelper', file_=f)
# equals to:
# r = itchat.send_file('t.pdf', 'filehelper')
print(r)
with open('t.png', 'rb') as f:
r = itchat.send_image(f, 'filehelper')
# equals to:
# r = itchat.send_image('t.png', 'filehelper')
print(r)
with open('t.mp4', 'rb') as f:
r = itchat.send_video(f, 'filehelper')
# equals to:
# r = itchat.send_video('t.mp4', 'filehelper')
print(r)
itchat.run()
增加了图片后缀自动判断
获取用户头像:
import itchat, shutil
itchat.auto_login(True)
r = itchat.get_head_img(picDir='tmp.unknown')
print(r)
if 'PostFix' in r:
shutil.move('tmp.unknown', 'tmp.%s' % r['PostFix'])
获取聊天图片:
import itchat, shutil
itchat.auto_login(True)
@itchat.msg_register(itchat.content.PICTURE)
def download(msg):
r = msg['Text']('tmp.unknown')
print(r)
if 'PostFix' in r:
shutil.move('tmp.unknown', 'tmp.%s' % r['PostFix'])
itchat.run()
增加了qrCallback中的终止登陆功能
import itchat
def qrCallback(uuid, status, qrcode):
if status == '400':
itchat.logout()
itchat.auto_login(True, qrCallback=qrCallback)
if itchat.originInstance.alive:
itchat.run()
else:
print('qrcode timeout and exit')
Login without scanning qrcode
你可以这样测试:
首先成功登陆一次:
import itchat
itchat.auto_login(True)
之后在手机上将该登录状态登出。(模拟各类登出)
之后重新运行登陆,你将不需要扫码直接在手机上获得登陆推送。
import itchat
itchat.auto_login(True)
itchat.send('Login without qrcode!', 'filehelper')
在上次登陆后没有通过其他途径登陆该微信的情况下,再次登录将不再需要扫码,直接收到登陆推送。
Clear useless loggings
Exceptions in registered functions will now be shown in warning level.
When wechat domain is not available, exceptions will also be shown in warning level.
群聊用户删除后不更新本地群聊存储修复
这个问题简而言之就是退了一个用户,之后本地不会删除该用户。
这里给出一个群聊人数监控的示例:
#coding=utf8
import logging
import itchat
from itchat.content import *
logger = logging.getLogger('itchat')
groupName = u'萝卜群'
groupMemberCount = -1
groupUserName = None
itchat.auto_login(True)
group = itchat.search_chatrooms(name=groupName)[0]
if not group['MemberList']:
logger.info('no member list detected')
group = itchat.update_chatroom(group['UserName'])
groupMemberCount = len(group['MemberList'])
groupUserName = group['UserName']
logger.info('%s: %s' % (groupName, groupMemberCount))
@itchat.msg_register(SYSTEM)
def detect_member(msg):
global groupMemberCount
if msg['SystemInfo'] != 'chatrooms':
logger.info(msg['SystemInfo'])
elif groupUserName not in msg['Text']:
logger.info(msg['Text'])
else:
newGroup = itchat.search_chatrooms(userName=groupUserName)
logger.info('%s member updated: %s -> %s' %(
groupName, groupMemberCount, len(newGroup['MemberList'])))
groupMemberCount = len(newGroup['MemberList'])
itchat.run(True)
v1.2.12
更新了大文件的上传
这个不用多说了吧,你试试大文件就好了
更新了新的发送协议
微信更新了附件的发送协议,所以我也更新了一下