def getallname(data): chatdict = {} db_file = data flag = 1 parser = WeChatDBParser(db_file) chats = parser.msgs_by_chat.keys() for k in chats: name = parser.contacts[k] if name: chatdict[name] = k else: chatdict["chatID_"+str(flag)] = k flag+=1 return chatdict
sys.exit( "Usage: {0} <path to decrypted_database.db> <path to avatar.index> <path to resource> <name> <output html>" .format(sys.argv[0])) from common.textutil import ensure_unicode from wechat.parser import WeChatDBParser from wechat.res import Resource from wechat.render import HTMLRender db_file = sys.argv[1] avt_db = sys.argv[2] resource_dir = sys.argv[3] name = ensure_unicode(sys.argv[4]) output_file = sys.argv[5] parser = WeChatDBParser(db_file) res = Resource(resource_dir, avt_db) try: msgs = parser.msgs_by_talker[name] except: sys.stderr.write(u"Valid Contacts: {}\n".format(u'\n'.join( parser.msgs_by_talker.keys()))) sys.stderr.write(u"Couldn't find that contact {}.".format(name)) sys.exit(1) render = HTMLRender(parser, res) htmls = render.render_msgs(msgs) if len(htmls) == 1: with open(output_file, 'w') as f:
parser.add_argument('--avt', default='avatar.index', help='path to avatar.index file') parser.add_argument('--res', default='resource', help='reseource directory') args = parser.parse_args() return args if __name__ == '__main__': args = get_args() name = ensure_unicode(args.name) parser = WeChatDBParser(args.db) try: chatid = parser.get_chat_id(args.name) except KeyError: sys.stderr.write(u"Valid Contacts: {}\n".format(u'\n'.join( parser.all_chat_nicknames))) sys.stderr.write(u"Couldn't find the chat {}.".format(name)) sys.exit(1) res = Resource(parser, args.res, args.avt) msgs = parser.msgs_by_chat[chatid] logger.info(f"Number of Messages for chatid {chatid}: {len(msgs)}") assert len(msgs) > 0 render = HTMLRender(parser, res)
@author: czfshine """ import sys sys.path.append("./wechat-dump/") import wechat from wechat.parser import WeChatDBParser import sys, os import pandas as pd # config: base = "D:\\wechat\\" # database parser parser = WeChatDBParser(base + "decrypted.db") def getallmsg(parser): a = [] for k in parser.msgs_by_chat: a.extend(parser.msgs_by_chat[k]) return a def topandas(msgs): name = [ 'createTime', 'chat_nickname', 'talker', 'content', 'type', 'chat', 'content_xml_ready', 'imgPath', 'msgSvrId', 'msg_str' ] d = {}