Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
修正fetchgroups中的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pandolia committed Feb 16, 2017
1 parent ec84662 commit 6a268f4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion qqbot/qcontacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __str__(self):
return self.shortRepr

def GetMemberName(self, memberUin):
return self.members.get(memberUin, 'NEWBIE')
return self.members.get(memberUin, '##UNKNOWN')

class QContacts:
def __init__(self):
Expand Down
5 changes: 3 additions & 2 deletions qqbot/qqbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import random, time, sys, subprocess

from qconf import QConf
from utf8logger import INFO, WARN
from utf8logger import INFO, WARN, DEBUG
from qsession import QLogin, QSession
from qterm import QTermServer
from common import Utf8Partition
Expand Down Expand Up @@ -94,6 +94,7 @@ def fetchForever(self):
contacts = self.fetch()
except (QSession.Error, Exception):
WARN(' fetchForever 方法出错')
DEBUG('', exc_info=True)
else:
yield Message('fetchcomplete', contacts=contacts)

Expand All @@ -107,7 +108,7 @@ def onPollComplete(self, message):
try:
contact = self.Get(ctype, uin=fromUin)[0]
except IndexError:
contact = QContact(ctype, uin=fromUin, name='NEWBIE', qq='')
contact = QContact(ctype, uin=fromUin, name='##UNKNOWN', qq='')

if ctype == 'buddy':
memberName = ''
Expand Down
30 changes: 20 additions & 10 deletions qqbot/qsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,23 @@ def fetchGroups(self, contacts, silence=True):
INFO('登录 Step7 - 获取群列表')
INFO('=' * 60)

result = self.smartRequest(
url = 'http://s.web2.qq.com/api/get_group_name_list_mask2',
data = {
'r': JsonDumps({'vfwebqq':self.vfwebqq, 'hash':self.hash})
},
Referer = ('http://d1.web2.qq.com/proxy.html?v=20151105001&'
'callback=1&id=2')
)
for i in range(5):
result = self.smartRequest(
url = 'http://s.web2.qq.com/api/get_group_name_list_mask2',
data = {
'r': JsonDumps({'vfwebqq':self.vfwebqq, 'hash':self.hash})
},
Referer = ('http://d1.web2.qq.com/proxy.html?v=20151105001&'
'callback=1&id=2')
)
if 'gmarklist' in result:
break
else:
ERROR('获取群列表出错,等待 3 秒后再次尝试一次')
time.sleep(3)
else:
CRITICAL('无法获取到群列表')
raise QSession.Error

markDict = dict((d['uin'],d['markname']) for d in result['gmarklist'])

Expand Down Expand Up @@ -476,12 +485,13 @@ def urlGet(self, url, data=None, **kw):
except (requests.exceptions.SSLError, AttributeError):
# by @staugur, @pandolia
if self.session.verify:
self.session.verify = False
time.sleep(5)
ERROR('无法和腾讯服务器建立私密连接,'
' 10 秒后将尝试使用非私密连接和腾讯服务器通讯。'
'若您不希望使用非私密连接,请按 Ctrl+C 退出本程序。')
time.sleep(10)
WARN('已开始尝试使用非私密连接和腾讯服务器通讯。')
WARN('开始尝试使用非私密连接和腾讯服务器通讯。')
self.session.verify = False
requests.packages.urllib3.disable_warnings(
requests.packages.urllib3.exceptions.
InsecureRequestWarning
Expand Down
2 changes: 1 addition & 1 deletion qqbot/qterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def qterm(port):
while True:
front, resp = partition(resp)
if resp:
RAWINPUT(front+'...')
RAWINPUT(front+'--More--')
else:
resp = front
break
Expand Down
3 changes: 2 additions & 1 deletion qqbot/utf8logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ def RAWINPUT(msg):
s = s.decode(sys.stdin.encoding).encode('utf8')
return s

PRINT = lambda s: utf8Stdout.write(s + '\n')
def PRINT(s, end='\n'):
return utf8Stdout.write(s+end)

0 comments on commit 6a268f4

Please sign in to comment.