Merge pull request #4 from BillBillBillBill/master

修复linux下不能打开文件的问题和一个获取分享信息时出现keyerror崩溃的问题
This commit is contained in:
Urinx
2016-02-07 11:38:57 +08:00
+17 -7
View File
@@ -8,6 +8,8 @@ import xml.dom.minidom
import json
import time, re, sys, os, random
import multiprocessing
import platform
from collections import defaultdict
def catchKeyboardInterrupt(fn):
def wrapper(*args):
@@ -238,7 +240,8 @@ class WebWeixin(object):
'rr': ~int(time.time())
}
dic = self._post(url, params)
if self.DEBUG: print dic
if self.DEBUG:
print json.dumps(dic, indent=4)
if dic['BaseResponse']['Ret'] == 0:
self.SyncKey = dic['SyncKey']
@@ -353,13 +356,13 @@ class WebWeixin(object):
else:
print '自动回复失败'
elif msgType == 3:
img = self.webwxgetmsgimg(msgid)
print '%s 给你发送了一张图片: %s' % (name, img)
os.system('open %s' % img)
image = self.webwxgetmsgimg(msgid)
print '%s 给你发送了一张图片: %s' % (name, image)
self._safe_open(image)
elif msgType == 34:
voice = self.webwxgetvoice(msgid)
print '%s 给你发了一段语音: %s' % (name, voice)
os.system('open %s' % voice)
self._safe_open(voice)
elif msgType == 42:
info = msg['RecommendInfo']
print '%s 给你发送了一张名片:' % name
@@ -372,9 +375,10 @@ class WebWeixin(object):
elif msgType == 47:
url = self._searchContent('cdnurl', content)
print '%s 给你发了一个动画表情,点击下面链接查看:\n%s' % (name, url)
os.system('open %s' % url)
self._safe_open(url)
elif msgType == 49:
appMsgType = {5:'链接', 3:'音乐'}
appMsgType = defaultdict(lambda : "")
appMsgType.update({5:'链接', 3:'音乐', 7:'微博'})
print '%s 给你分享了一个%s:' % (name, appMsgType[msg['AppMsgType']])
print '========================='
print '= 标题: %s' % msg['FileName']
@@ -471,6 +475,12 @@ class WebWeixin(object):
elif text[:3] == 'i->':
print '发送图片'
def _safe_open(self, path):
if platform.system() == "Linux":
os.system("xdg-open %s &" % path)
else:
os.system('open %s &' % path)
def _run(self, str, func, *args):
self._echo(str)
if func(*args): print '成功'