video/links
This commit is contained in:
+17
-2
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: Msg.py
|
||||
# Date: Fri Nov 21 14:10:21 2014 +0800
|
||||
# Date: Sat Nov 22 08:09:56 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
from datetime import datetime
|
||||
@@ -14,7 +14,7 @@ TYPE_SPEAK = 34
|
||||
TYPE_VIDEO = 43
|
||||
TYPE_EMOJI = 47
|
||||
TYPE_LOCATION = 48
|
||||
TYPE_LINK = 49
|
||||
TYPE_LINK = 49 # link share or file from web
|
||||
TYPE_VOIP = 50
|
||||
TYPE_SYSTEM = 10000
|
||||
|
||||
@@ -52,6 +52,18 @@ class WeChatMsg(object):
|
||||
except:
|
||||
pass
|
||||
return ret + " ({},{})".format(loc['x'], loc['y'])
|
||||
elif self.type == TYPE_VOIP:
|
||||
return "REQUEST VIDEO CHAT"
|
||||
elif self.type == TYPE_LINK:
|
||||
soup = BeautifulSoup(self.content)
|
||||
url = soup.find('url').text
|
||||
if not url:
|
||||
title = soup.find('title').text
|
||||
assert title, "No title or url found in TYPE_LINK"
|
||||
return u"FILE:{}".format(title)
|
||||
return u"URL:{}".format(url)
|
||||
elif self.type == TYPE_VIDEO:
|
||||
return "VIDEO"
|
||||
else:
|
||||
return self.content
|
||||
|
||||
@@ -66,3 +78,6 @@ class WeChatMsg(object):
|
||||
return ret.encode('utf-8')
|
||||
else:
|
||||
return ret
|
||||
|
||||
def __lt__(self, r):
|
||||
return self.createTime < r.createTime
|
||||
|
||||
+10
-8
@@ -1,11 +1,13 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: Parser.py
|
||||
# Date: Fri Nov 21 14:36:18 2014 +0800
|
||||
# Date: Sat Nov 22 08:07:56 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import sqlite3
|
||||
from collections import defaultdict
|
||||
import itertools
|
||||
|
||||
from .Msg import WeChatMsg
|
||||
from .utils import ensure_unicode
|
||||
|
||||
@@ -56,14 +58,14 @@ SELECT {} FROM message
|
||||
for msg in v:
|
||||
msg.talker = k
|
||||
|
||||
def _find_msg_by_type(self):
|
||||
def _find_msg_by_type(self, msgs=None):
|
||||
ret = []
|
||||
for v in self.msgs_by_talker.itervalues():
|
||||
for msg in v:
|
||||
if msg.type == 34:
|
||||
print msg
|
||||
print
|
||||
return ret
|
||||
if msgs is None:
|
||||
msgs = itertools.chain.from_iterable(self.msgs_by_talker.itervalues())
|
||||
for msg in msgs:
|
||||
if msg.type == 43:
|
||||
ret.append(msg)
|
||||
return sorted(ret)
|
||||
|
||||
def parse(self):
|
||||
self._parse_contact()
|
||||
|
||||
Reference in New Issue
Block a user