Skip to content

Commit

Permalink
Changes from issues & PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecodersh committed Feb 28, 2018
1 parent fc81ba6 commit e2a5ba0
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 39 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ A: 有些账号是天生无法给自己的账号发送信息的,建议使用`f

[yaphone/itchat4j][yaphone-itchat4j]: 用Java扩展个人微信号的能力

[kanjielu/jeeves][kanjielu-jeeves]: 使用springboot开发的微信机器人

## 问题和建议

如果有什么问题或者建议都可以在这个[Issue][issue#1]和我讨论
Expand Down Expand Up @@ -306,4 +308,5 @@ A: 有些账号是天生无法给自己的账号发送信息的,建议使用`f
[Mojo-Weixin]: https://github.com/sjdy521/Mojo-Weixin
[HanSon-vbot]: https://github.com/hanson/vbot
[yaphone-itchat4j]: https://github.com/yaphone/itchat4j
[kanjielu-jeeves]: https://github.com/kanjielu/jeeves
[issue#1]: https://github.com/littlecodersh/ItChat/issues/1
4 changes: 2 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A wechat robot can handle all the basic messages with only less than 30 lines of

And it's similiar to itchatmp (api for wechat massive platform), learn once and get two tools.

Now Wechat is an important part of personal life, hopefully this repo can help you extend your personal wechat account's functionality and enbetter user's experience with wechat.
Now Wechat is an important part of personal life, hopefully this repo can help you extend your personal wechat account's functionality and better user's experience with wechat.

## Installation

Expand Down Expand Up @@ -168,7 +168,7 @@ itchat.search_friends(wechatAccount='littlecodersh')
itchat.search_friends(name='LittleCoder机器人', wechatAccount='littlecodersh')
```

There are detailed information about searching and getting of massive platforms and chatrooms in document.
There is detailed information about searching and getting of massive platforms and chatrooms in document.

### Download and send attachments

Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def start_receiving(self, finishCallback=None):
def get_msg(self):
''' fetch messages
for fetching
- method blocks for sometime util
- method blocks for sometime until
- new messages are to be received
- or anytime they like
- synckey is updated with returned synccheckkey
Expand Down
13 changes: 6 additions & 7 deletions itchat/components/contact.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os, time, re, io
import time, re, io
import json, copy
import traceback, logging

import requests
import logging

from .. import config, utils
from ..returnvalues import ReturnValue
from ..storage import contact_change, templates
from ..storage import contact_change
from ..utils import update_info_dict

logger = logging.getLogger('itchat')
Expand Down Expand Up @@ -148,8 +146,9 @@ def update_local_chatrooms(core, l):
del oldChatroom['MemberList'][i]
# - update OwnerUin
if oldChatroom.get('ChatRoomOwner') and oldChatroom.get('MemberList'):
oldChatroom['OwnerUin'] = utils.search_dict_list(oldChatroom['MemberList'],
'UserName', oldChatroom['ChatRoomOwner']).get('Uin', 0)
owner = utils.search_dict_list(oldChatroom['MemberList'],
'UserName', oldChatroom['ChatRoomOwner'])
oldChatroom['OwnerUin'] = (owner or {}).get('Uin', 0)
# - update IsAdmin
if 'OwnerUin' in oldChatroom and oldChatroom['OwnerUin'] != 0:
oldChatroom['IsAdmin'] = \
Expand Down
2 changes: 1 addition & 1 deletion itchat/components/hotreload.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pickle, os
import logging, traceback
import logging

import requests

Expand Down
26 changes: 13 additions & 13 deletions itchat/components/login.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os, sys, time, re, io
import os, time, re, io
import threading
import json, xml.dom.minidom
import copy, pickle, random
import random
import traceback, logging
try:
from httplib import BadStatusLine
Expand Down Expand Up @@ -206,19 +206,19 @@ def web_init(self):
self.storageClass.userName = dic['User']['UserName']
self.storageClass.nickName = dic['User']['NickName']
# deal with contact list returned when init
contactList = dic.get('ContactList', [])
chatroomList, otherList = [], []
for m in contactList:
if m['Sex'] != 0:
otherList.append(m)
elif '@@' in m['UserName']:
contactList = dic.get('ContactList', [])
chatroomList, otherList = [], []
for m in contactList:
if m['Sex'] != 0:
otherList.append(m)
elif '@@' in m['UserName']:
m['MemberList'] = [] # don't let dirty info pollute the list
chatroomList.append(m)
elif '@' in m['UserName']:
# mp will be dealt in update_local_friends as well
otherList.append(m)
chatroomList.append(m)
elif '@' in m['UserName']:
# mp will be dealt in update_local_friends as well
otherList.append(m)
if chatroomList:
update_local_chatrooms(self, chatroomList)
update_local_chatrooms(self, chatroomList)
if otherList:
update_local_friends(self, otherList)
return dic
Expand Down
22 changes: 13 additions & 9 deletions itchat/components/messages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os, time, re, io
import json
import mimetypes, hashlib
import traceback, logging
import logging
from collections import OrderedDict

import requests
Expand Down Expand Up @@ -47,7 +47,7 @@ def download_fn(downloadDir=None):
def produce_msg(core, msgList):
''' for messages types
* 40 msg, 43 videochat, 50 VOIPMSG, 52 voipnotifymsg
* 53 webwxvoipnotifymsg, 9999 sysnotice
* 53 webwxvoipnotifymsg, 9999 sysnotice
'''
rl = []
srl = [40, 43, 50, 52, 53, 9999]
Expand Down Expand Up @@ -89,7 +89,7 @@ def produce_msg(core, msgList):
'Type': 'Text',
'Text': m['Content'],}
elif m['MsgType'] == 3 or m['MsgType'] == 47: # picture
download_fn = get_download_fn(core,
download_fn = get_download_fn(core,
'%s/webwxgetmsgimg' % core.loginInfo['url'], m['NewMsgId'])
msg = {
'Type' : 'Picture',
Expand Down Expand Up @@ -141,7 +141,11 @@ def download_video(videoDir=None):
'FileName' : '%s.mp4' % time.strftime('%y%m%d-%H%M%S', time.localtime()),
'Text': download_video, }
elif m['MsgType'] == 49: # sharing
if m['AppMsgType'] == 6:
if m['AppMsgType'] == 0: # chat history
msg = {
'Type': 'Note',
'Text': m['Content'], }
elif m['AppMsgType'] == 6:
rawMsg = m
cookiesList = {name:data for name,data in core.s.cookies.items()}
def download_atta(attaDir=None):
Expand Down Expand Up @@ -169,7 +173,7 @@ def download_atta(attaDir=None):
'Type': 'Attachment',
'Text': download_atta, }
elif m['AppMsgType'] == 8:
download_fn = get_download_fn(core,
download_fn = get_download_fn(core,
'%s/webwxgetmsgimg' % core.loginInfo['url'], m['NewMsgId'])
msg = {
'Type' : 'Picture',
Expand Down Expand Up @@ -239,7 +243,7 @@ def produce_group_chat(core, msg):
member = utils.search_dict_list((chatroom or {}).get(
'MemberList') or [], 'UserName', actualUserName)
if member is None:
chatroom = core.update_chatroom(msg['FromUserName'])
chatroom = core.update_chatroom(chatroomUserName)
member = utils.search_dict_list((chatroom or {}).get(
'MemberList') or [], 'UserName', actualUserName)
if member is None:
Expand Down Expand Up @@ -267,7 +271,7 @@ def send_raw_msg(self, msgType, content, toUserName):
'ToUserName': (toUserName if toUserName else self.storageClass.userName),
'LocalID': int(time.time() * 1e4),
'ClientMsgId': int(time.time() * 1e4),
},
},
'Scene': 0, }
headers = { 'ContentType': 'application/json; charset=UTF-8', 'User-Agent' : config.USER_AGENT }
r = self.s.post(url, headers=headers,
Expand Down Expand Up @@ -515,8 +519,8 @@ def revoke(self, msgId, toUserName, localId=None):
"ClientMsgId": localId or str(time.time() * 1e3),
"SvrMsgId": msgId,
"ToUserName": toUserName}
headers = {
'ContentType': 'application/json; charset=UTF-8',
headers = {
'ContentType': 'application/json; charset=UTF-8',
'User-Agent' : config.USER_AGENT }
r = self.s.post(url, headers=headers,
data=json.dumps(data, ensure_ascii=False).encode('utf8'))
Expand Down
6 changes: 2 additions & 4 deletions itchat/core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging

import requests

from . import config, storage, utils, log
from . import storage
from .components import load_components

class Core(object):
Expand Down Expand Up @@ -127,7 +125,7 @@ def start_receiving(self, exitCallback=None, getReceivingFnOnly=False):
def get_msg(self):
''' fetch messages
for fetching
- method blocks for sometime util
- method blocks for sometime until
- new messages are to be received
- or anytime they like
- synckey is updated with returned synccheckkey
Expand Down
2 changes: 0 additions & 2 deletions itchat/returnvalues.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#coding=utf8
import sys

TRANSLATE = 'Chinese'

class ReturnValue(dict):
Expand Down

0 comments on commit e2a5ba0

Please sign in to comment.