From efb24cb90e3352208a323ac24cc0514d92c4b07d Mon Sep 17 00:00:00 2001 From: liuyang Date: Tue, 17 May 2016 11:47:36 +0800 Subject: [PATCH] add msg type 49 content --- wxbot.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/wxbot.py b/wxbot.py index 301a29c..52b45fd 100644 --- a/wxbot.py +++ b/wxbot.py @@ -3,6 +3,7 @@ import os import sys +import traceback import webbrowser import pyqrcode import requests @@ -39,13 +40,17 @@ def show_image(file_path): webbrowser.open(file_path) class SafeSession(requests.Session): - def request(self, *args, **kwargs): + 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(*args, **kwargs) - except: - pass - return super(SafeSession, self).request(*args, **kwargs) + return super(SafeSession, self).request(method, url, params, data, headers, cookies, files, auth, + timeout, + allow_redirects, proxies, hooks, stream, verify, cert, json) + except Exception as e: + print e.message,traceback.format_exc() + continue class WXBot: @@ -244,6 +249,7 @@ class WXBot: + @staticmethod def get_contact_prefer_name(name): if name is None: @@ -475,7 +481,9 @@ class WXBot: 'title': msg['FileName'], 'desc': self.search_content('des', content, 'xml'), 'url': msg['Url'], - 'from': self.search_content('appname', content, 'xml')} + 'from': self.search_content('appname', content, 'xml'), + 'content':msg.get('content')#有的公众号会发一次性3 4条链接一个大图,如果只url那只能获取第一条,content里面有所有的链接 + } if self.DEBUG: print ' %s[Share] %s' % (msg_prefix, app_msg_type) print ' --------------------------' @@ -483,6 +491,7 @@ class WXBot: print ' | desc: %s' % self.search_content('des', content, 'xml') print ' | link: %s' % msg['Url'] print ' | from: %s' % self.search_content('appname', content, 'xml') + print ' | content: %s' % msg.get('content')[:20] print ' --------------------------' elif mtype == 62: