add Res.py

This commit is contained in:
ppwwyyxx
2014-11-22 21:59:59 +08:00
parent d819eca642
commit d3c20d3490
3 changed files with 48 additions and 4 deletions
+6 -3
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: Parser.py
# Date: Sat Nov 22 08:07:56 2014 +0800
# Date: Sat Nov 22 20:48:04 2014 +0800
# Author: Yuxin Wu <[email protected]>
import sqlite3
@@ -9,6 +9,7 @@ from collections import defaultdict
import itertools
from .Msg import WeChatMsg
from .Res import Resource
from .utils import ensure_unicode
""" tables in concern:
@@ -22,7 +23,7 @@ rcontact
"""
class WeChatDBParser(object):
def __init__(self, db_fname):
def __init__(self, db_fname, res_dir=None):
""" db_fname: EnMicroMsg.db"""
self.db_fname = db_fname
self.db_conn = sqlite3.connect(self.db_fname)
@@ -30,6 +31,8 @@ class WeChatDBParser(object):
self.contacts = {}
self.msgs_by_talker = defaultdict(list)
self.res = Resource(res_dir) if res_dir else None
def _parse_contact(self):
contacts = self.cc.execute(
"""
@@ -63,7 +66,7 @@ SELECT {} FROM message
if msgs is None:
msgs = itertools.chain.from_iterable(self.msgs_by_talker.itervalues())
for msg in msgs:
if msg.type == 43:
if msg.type == 34:
ret.append(msg)
return sorted(ret)