Skip to content

Commit

Permalink
Merge pull request liuwons#62 from liuyang007/master
Browse files Browse the repository at this point in the history
增加链接重试, 增加从群名称中查找id
  • Loading branch information
liuwons committed May 13, 2016
2 parents 619e0d0 + 3aba6a5 commit cd4f757
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion wxbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def show_image(file):
else:
webbrowser.open(file)

class SafeSession(requests.Session):
def request(self, method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None,
timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None,
json=None):
for i in range(3):
try:
return super(SafeSession, self).request(method, url, params, data, headers, cookies, files, auth,
timeout,
allow_redirects, proxies, hooks, stream, verify, cert, json)
except:
continue


class WXBot:
"""WXBot功能类"""
Expand All @@ -56,7 +68,7 @@ def __init__(self):
self.sync_key = []
self.sync_host = ''

self.session = requests.Session()
self.session = SafeSession()
self.session.headers.update({'User-Agent': 'Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5'})
self.conf = {'qr': 'png'}

Expand Down Expand Up @@ -684,6 +696,14 @@ def get_user_id(self, name):
return contact['UserName']
elif 'DisplayName' in contact and contact['DisplayName'] == name:
return contact['UserName']
for group in self.group_list:
if 'RemarkName' in group and group['RemarkName'] == name:
return group['UserName']
if 'NickName' in group and group['NickName'] == name:
return group['UserName']
if 'DisplayName' in group and group['DisplayName'] == name:
return group['UserName']

return ''

def send_msg(self, name, word, isfile=False):
Expand Down

0 comments on commit cd4f757

Please sign in to comment.