def get_friends(self): friends, groups = self._get_friends_groups_id() contacts_path = self.root.GetByPath("/databases/wa.db") wal_path = self.root.GetByPath("/databases/wa.db-wal") if contacts_path is None: return if wal_path is None: connection = System.Data.SQLite.SQLiteConnection( 'Data Source = {0}; ReadOnly = True'.format( contacts_path.PathWithMountPoint)) else: moveFileto(contacts_path.PathWithMountPoint, self.cache) moveFileto(wal_path.PathWithMountPoint, self.cache) tmp_path = self.cache + "/wa.db" connection = System.Data.SQLite.SQLiteConnection( 'Data Source = {0}'.format(tmp_path)) try: connection.Open() cmd = System.Data.SQLite.SQLiteCommand(connection) cmd.CommandText = ''' select * from wa_contacts where is_whatsapp_user = 1 ''' reader = cmd.ExecuteReader() if reader: while reader.Read(): if canceller.IsCancellationRequested: return friend_id = GetString(reader, 1) if friend_id.find("net") != -1 and friend_id in friends: friend = model_im.Friend() friend.source = contacts_path.AbsolutePath friend.account_id = self.account_id friend.friend_id = friend_id friend.nickname = GetString(reader, 7) self.contacts_dicts[friend_id] = GetString(reader, 7) friend.telephone = GetString(reader, 5) friend.signature = GetString(reader, 3) friend.type = model_im.FRIEND_TYPE_FRIEND try: self.whatsapp.db_insert_table_friend(friend) except Exception as e: pass else: friend = model_im.Friend() friend.source = contacts_path.AbsolutePath friend.account_id = self.account_id friend.type = model_im.FRIEND_TYPE_FRIEND for i in friends: friend.friend_id = i friend.nickname = "unknown" try: self.whatsapp.db_insert_table_friend(friend) except Exception as e: pass except Exception as e: pass if connection != None: connection.Close() self.whatsapp.db_commit()
def parse_friend(self, node): '''解析好友数据''' try: db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return ts = SQLiteParser.TableSignature('users') for rec in db.ReadTableRecords(ts, self.extractDeleted, True): try: friend = model_im.Friend() if canceller.IsCancellationRequested: break if IsDBNull(rec['id_c'].Value) or rec['id_c'].Value == 0: continue friend = model_im.Friend() userDir = node.PathWithMountPoint userid = re.findall('\d+', userDir)[-1] phone_number = None if not IsDBNull(rec['settings_c'].Value): phone_len = int(rec['settings_c'].Value[5]) data = str(bytes(rec['settings_c'].Value)) phone_number = data.encode('hex')[12:(phone_len+6)*2:].decode('hex').decode('utf-8') picture = None if not IsDBNull(rec['pictures_c'].Value): lst = [] dic = {} for i, byte in enumerate(rec['pictures_c'].Value): if int(byte) == 1: #start dic = {} dic['start'] = i+1 if int(byte) == 26: #end dic['end'] = i lst.append(dic) data = str(bytes(rec['pictures_c'].Value)) if len(lst) != 0: picture = data.encode('hex')[lst[0]['start']*2:lst[0]['end']*2:].decode('hex').decode('utf-8') friend.account_id = userid friend.friend_id = self._db_record_get_int_value(rec, 'id_c') if friend.friend_id == 0: continue friend.nickname = self._db_record_get_string_value(rec, 'name_c') if friend.friend_id not in self.friend.keys(): self.friend[friend.friend_id] = friend.nickname friend.photo = picture friend.fullname = friend.nickname friend.telephone = phone_number friend.age = self._db_record_get_int_value(rec, 'age_c') gender = self._db_record_get_int_value(rec, 'gender_c') friend.gender = 2 if gender == 1 else 1 if gender == 2 else 0 friend.signature = self._db_record_get_string_value(rec, 'description_c') friend.source = node.AbsolutePath friend.deleted = rec.IsDeleted self.db_insert_table_friend(friend) except: traceback.print_exc() self.db_commit() except Exception as e: print(e)
def get_contacts(self): if self.user is None: return dbPath = self.root.GetByPath('../../../Documents/' + self.user + '/msg2.db') db = SQLiteParser.Database.FromNode(dbPath) if db is None: return if 'msglog' in db.Tables: ts = SQLiteParser.TableSignature('msglog') SQLiteParser.Tools.AddSignatureToTable( ts, "id", SQLiteParser.FieldType.Text, SQLiteParser.FieldConstraints.NotNull) for rec in db.ReadTableRecords(ts, self.extract_deleted): if canceller.IsCancellationRequested: return contact = {'deleted': rec.Deleted, 'repeated': 0} contactid = rec['id'].Value type = rec['msg_type'].Value if contactid in self.contacts: continue else: self.contacts[contactid] = contact if type == 1: friend = model_im.Friend() friend.deleted = 0 if rec.Deleted == DeletedState.Intact else 1 friend.repeated = contact.get('repeated', 0) friend.source = dbPath.AbsolutePath friend.account_id = self.user friend.friend_id = contactid friend.type = model_im.FRIEND_TYPE_FRIEND self.csm.db_insert_table_friend(friend) if type == 2: chatroom = model_im.Chatroom() chatroom.deleted = 0 if rec.Deleted == DeletedState.Intact else 1 chatroom.repeated = contact.get('repeated', 0) chatroom.source = dbPath.AbsolutePath chatroom.account_id = self.user chatroom.chatroom_id = contactid self.csm.db_insert_table_chatroom(chatroom) if type == 6: friend = model_im.Friend() friend.deleted = 0 if rec.Deleted == DeletedState.Intact else 1 friend.repeated = contact.get('repeated', 0) friend.source = dbPath.AbsolutePath friend.account_id = self.user friend.friend_id = contactid friend.type = model_im.FRIEND_TYPE_SUBSCRIBE self.csm.db_insert_table_friend(friend) self.csm.db_commit()
def parse_relation_recovery(self, db_node, account_id): if db_node is None: return db = SQLiteParser.Database.FromNode(db_node) ts = SQLiteParser.TableSignature('user') sb = SQLiteParser.Tools.AddSignatureToTable(ts, "MOMOID", SQLiteParser.FieldType.Text, SQLiteParser.FieldConstraints.NotNull) for rec in db.ReadTableDeletedRecords(ts, False): friend = model_im.Friend() friend.friend_id = str(unity_c37r.try_get_rec_value(rec, 'MOMOID', '')) friend.nickname = str(unity_c37r.try_get_rec_value(rec, 'NAME', "")) friend.signature = str(unity_c37r.try_get_rec_value(rec, 'SIGNATURE', "")) friend.telephone = str(unity_c37r.try_get_rec_value(rec, 'PHONENUMBER', '')) friend.photo = str(unity_c37r.try_get_rec_value(rec, 'PHOTOS', '')) friend.account_id = account_id friend.type = model_im.FRIEND_TYPE_FRIEND friend.deleted = 1 self.im.db_insert_table_friend(friend) ts = SQLiteParser.TableSignature('group') SQLiteParser.Tools.AddSignatureToTable(ts, "GID", SQLiteParser.FieldType.Text, SQLiteParser.FieldConstraints.NotNull) for rec in db.ReadTableDeletedRecords(ts, False): cm = model_im.Chatroom() cm.account_id = account_id cm.chatroom_id = str(unity_c37r.try_get_rec_value(rec, 'GID', "")) cm.name = str(unity_c37r.try_get_rec_value(rec, 'NAME', '')) cm.owner_id = str(unity_c37r.try_get_rec_value(rec, 'NAME', "")) cm.description = str(unity_c37r.try_get_rec_value(rec, 'SIGN', '')) cm.photo = str(unity_c37r.try_get_rec_value(rec, 'PHOTOS', '')) cm.deleted = 1 self.im.db_insert_table_chatroom(cm) self.im.db_commit()
def _generate_friend_table(self, friends_file): """ 创建friend table, 注意,dropbox 并没有联系人聊天之类的东西,这个联系人只在分享的有用 :param friends_file: 保存联系人的信息 :return: """ friends_info = Utils.json_loads(Utils.open_file(friends_file)).get( "contacts", None) if not friends_info: return for friend_info in friends_info: try: friend = model_im.Friend() friend.account_id = self.using_account.account_id friend.friend_id = self.__process_account_id( friend_info.get("account_info", {}).get("id", None)) friend.source = friends_file friend.photo = friend_info.get("account_info", {}).get("photo_url", None) friend.nickname = friend_info.get("name", {}).get("display", None) friend.email = friend_info.get("email_addresses", [None])[0] friend.telephone = friend_info.get("phone_numbers", [None])[0] self.model_im_col.db_insert_table_friend(friend) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def __recover_profile_table_friend(self): if not self.checking_account_recover_col.is_valid(): return ts = self.checking_account_recover_col.fetch_table( "profile", { "PROFILE_ID": "Text", "AVATAR_URL": "Text", "NICK": "Text", "IDENTITY_TYPE": "Text", "SIGNATURE": "Text", }) for rec in self.checking_account_recover_col.read_deleted_record(ts): try: friend = model_im.Friend() friend.deleted = 1 friend.source = self.checking_account_recover_col.db_path friend.account_id = self.using_account.account_id friend.source = self.checking_account_col.db_path friend.friend_id = rec['PROFILE_ID'].Value friend.photo = rec['AVATAR_URL'].Value friend.nickname = rec['NICK'].Value friend.signature = rec['SIGNATURE'].Value friend.type = self.__convert_friend_type( rec['IDENTITY_TYPE'].Value) self.model_im_col.db_insert_table_friend(friend) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def __recover_relation_table_friend(self): if not self.checking_account_recover_col.is_valid(): return ts = self.checking_account_recover_col.fetch_table( "relation", { "RELATION_ID": "Text", "IDENTITY_TYPE": "Text", "TARGET_REMARK_NAME": "Text", "AVATAR_URL": "Text", }) for rec in self.checking_account_recover_col.read_deleted_record(ts): try: friend = model_im.Friend() friend.deleted = 1 friend.source = self.checking_account_recover_col.db_path friend.friend_id = rec['RELATION_ID'].Value if self.__in_profile_table(friend.friend_id): continue friend.account_id = self.using_account.account_id friend.photo = rec['AVATAR_URL'].Value friend.nickname = rec['TARGET_REMARK_NAME'].Value friend.type = self.__convert_friend_type( rec['IDENTITY_TYPE'].Value) self.model_im_col.db_insert_table_friend(friend) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def get_friends(self, node, account_id): db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return if 'ZSMUSER' not in db.Tables: return tbs = SQLiteParser.TableSignature("ZSMUSER") for rec in db.ReadTableRecords(tbs, False): if canceller.IsCancellationRequested: return try: friend = model_im.Friend() friend.account_id = account_id friend.type = 1 if rec.Deleted == DeletedState.Deleted: friend.deleted = 1 friend.source = node.AbsolutePath if "ZACCID" in rec and (not rec["ZACCID"].IsDBNull): friend.friend_id = rec["ZACCID"].Value if "ZNICKNAME" in rec and (not rec["ZNICKNAME"].IsDBNull): friend.nickname = rec["ZNICKNAME"].Value self.contact_list[friend.friend_id] = friend.nickname if "ZAVATARURL" in rec and (not rec["ZAVATARURL"].IsDBNull): friend.photo = rec["ZAVATARURL"].Value if friend.account_id and friend.friend_id: self.bulletMessage.db_insert_table_friend(friend) except Exception as e: TraceService.Trace(TraceLevel.Info, e) self.bulletMessage.db_commit()
def _get_friends(self): conn = self.__get_con() conn.Open() cmd = System.Data.SQLite.SQLiteCommand(conn) cmd.CommandText = """select uid, name, status, data from users""" reader = cmd.ExecuteReader() while reader.Read(): try: friend = model_im.Friend() friend.friend_id = GetInt64(reader, 0) friend.account_id = self.account friend.source = self.root.GetByPath( self.account_db_path).PathWithMountPoint friend_info = TelegramDecodeHelper.decode_user( GetBlob(reader, 3)) if friend_info: friend.deleted = 0 if friend_info.deleted is False else 1 friend.telephone = friend_info.phone first_name = friend_info.first_name if friend_info.first_name else "" last_name = friend_info.last_name if friend_info.last_name else "" friend.nickname = first_name + " " + last_name self.model_col.db_insert_table_friend(friend) except Exception as e: print(e) reader.Close() cmd.Dispose() conn.Close() self.model_col.db_commit()
def decode_recover_friend(self): node = self.root.GetByPath("databases/agent-dao") if node is None: return db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return table = 'PERSON' ts = SQLiteParser.TableSignature(table) SQLiteParser.Tools.AddSignatureToTable( ts, "SN", SQLiteParser.FieldType.Text, SQLiteParser.FieldConstraints.NotNull) SQLiteParser.Tools.AddSignatureToTable( ts, "NAME", SQLiteParser.FieldType.Text, SQLiteParser.FieldConstraints.NotNull) for rec in db.ReadTableDeletedRecords(ts, False): try: friend = model_im.Friend() friend.account_id = self.using_account friend.source = self.icq_data_path friend.friend_id = rec["SN"].Value friend.nickname = rec["NAME"].Value friend.type = model_im.FRIEND_TYPE_FRIEND self.model_im_col.db_insert_table_friend(friend) except Exception as e: print("error happen", e) self.model_im_col.db_commit()
def _generate_friend_table(self): with self.cloud_p2p_col as db_col: sql = """SELECT uk, source, name, uname, nick_name, remark, avatar_url, intro, third FROM v_followlist;""" db_col.execute_sql(sql) while db_col.has_rest(): try: friend = model_im.Friend() friend.account_id = self.using_account.account_id friend.photo = db_col.get_string(6) friend.nickname = db_col.get_string(4) friend.friend_id = db_col.get_int64(0) friend.type = model_im.FRIEND_TYPE_FOLLOW if db_col.get_int64(1) == 2 else model_im.FRIEND_TYPE_FRIEND self.model_im_col.db_insert_table_friend(friend) except Exception as e: pass self.model_im_col.db_commit()
def create_fake_friend(self, ac, name): f = model_im.Friend() f.account_id = ac.uid f.nickname = name f.remark = name f.friend_id = random.randint(0, 0xffffffff) # 产生假ID return f
def _add_friend_record(self): with self.friend_col as db_col: sql = """SELECT converstionID, headIcon, headBG, alics, signatrue, closeLevel, comeFromStr, mutualFollow FROM userInfo;""" db_col.execute_sql(sql) while db_col.has_rest(): try: friend = model_im.Friend() friend.account_id = self._get_account_id_from_conversation_id( db_col.get_string(0)) if not friend.account_id: continue friend.friend_id = db_col.get_string( 0)[len(friend.account_id):] friend.signature = db_col.get_string(4) friend.nickname = db_col.get_string( 3) if db_col.get_string(3) else friend.signature friend.type = model_im.FRIEND_TYPE_MUTUAL_FOLLOW if db_col.get_string(7) == "1" \ else model_im.FRIEND_TYPE_STRANGER friend.source = db_col.db_path self.model_im_col.db_insert_table_friend(friend) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def decode_recover_friend(self): if not self.cl_recover_helper.is_valid(): return ts = self.cl_recover_helper.fetch_table("anketa", { "about": "Text", "birthdate": "Int", "city": "Text", "country": "Text", "emails": "Text", "gender": "Int", "nickname": "Text", "smsNumber": "Text", "abContactName": "Text", }) for rec in self.cl_recover_helper.read_deleted_record(ts): if canceller.IsCancellationRequested: return try: friend = model_im.Friend() friend.source = self.cl_db_path friend.signature = rec["about"].Value friend.birthday = self.__convert_timestamp(rec["birthdate"].Value) friend.address = rec["country"].Value + rec["city"].Value friend.email = rec["emails"].Value friend.gender = self.__convert_gender(rec["gender"].Value) friend.nickname = rec["nickname"].Value friend.telephone = rec["smsNumber"].Value friend.type = model_im.FRIEND_TYPE_FRIEND friend.deleted = 1 self.model_im_col.db_insert_table_friend(friend) except Exception as e: print("debug error", e) self.model_im_col.db_commit()
def _get_friend_table(self): with self.cl_db_col as db_col: sql = """SELECT contact.pid, anketa.about, anketa.birthdate, anketa.city, anketa.country, anketa.emails, anketa.gender, anketa.nickname, anketa.smsNumber, anketa.abContactName FROM contact LEFT JOIN anketa ON contact._rowid_ = anketa.contactID WHERE contact.groupId in (1, 2, 3) AND contact.userType = 2;""" db_col.execute_sql(sql) while db_col.has_rest(): try: friend = model_im.Friend() friend.source = self.cl_db_path friend.account_id, _, friend.friend_id = db_col.get_string(0).split("|") if friend.account_id == friend.friend_id: continue friend.signature = db_col.get_string(1) friend.birthday = self.__convert_timestamp(db_col.get_int64(2)) friend.address = db_col.get_string(4) + db_col.get_string(3) friend.email = db_col.get_string(5) friend.gender = self.__convert_gender(db_col.get_int64(6)) friend.nickname = db_col.get_string(9) friend.telephone = db_col.get_string(8) friend.type = model_im.FRIEND_TYPE_FRIEND self.model_im_col.db_insert_table_friend(friend) except Exception as e: print("debug error", e) self.model_im_col.db_commit()
def _generate_friend_table(self): with self.checking_col as db_col: sql = """SELECT nsp_data FROM {};""".format(self.table_name["profilecache"]) db_col.execute_sql(sql) while db_col.has_rest(): try: friend_info = json.loads(db_col.get_string(0)) if friend_info.get("isManuallyAdded", None) is None: continue friend = model_im.Friend() friend.source = db_col.db_path friend.account_id = self.using_account.account_id friend_type, friend.friend_id = friend_info["mri"].split(":", 1) if friend.account_id == friend.friend_id or friend_type not in ("4", "8"): continue friend.signature = friend_info.get("mood", None) friend.gender = self.__convert_gender(friend_info.get("gender", 0)) friend.nickname = friend_info.get("displayNameOverride", None) friend.telephone = self.__choose_phone_number(friend_info.get("phones", [])) friend.photo = friend_info.get("thumbUrl", None) friend.type = model_im.FRIEND_TYPE_FRIEND if friend_type == "8" else None friend.birthday = self._handle_birthday(friend_info.get("birthday", None)) if friend_info.get("city") or friend_info.get("country"): friend.address = friend_info.get("city", "") + " " + friend_info.get("country", "") self.model_im_col.db_insert_table_friend(friend) except Exception as e: pass self.model_im_col.db_commit()
def _recover_friend_record(self): recover_col = self.friend_recover_col if not recover_col.is_valid(): return ts = recover_col.get_table( "userInfo", { "converstionID": [FieldType.Text, FieldConstraints.NotNull], "signatrue": [FieldType.Text, FieldConstraints.NotNull], "comeFromStr": [FieldType.Text, FieldConstraints.NotNull], }) for record in recover_col.read_deleted_records(ts): try: friend = model_im.Friend() friend.account_id = self._get_account_id_from_conversation_id( record['converstionID'].Value) if not record['converstionID'].Value.startswith( friend.account_id): continue friend.friend_id = record['converstionID'].Value[ len(friend.account_id):] friend.signature = record['signatrue'].Value friend.nickname = friend.signature friend.type = model_im.FRIEND_TYPE_MUTUAL_FOLLOW if record['mutualFollow'].Value == "1" \ else model_im.FRIEND_TYPE_STRANGER friend.source = recover_col.db_path self.model_im_col.db_insert_table_friend(friend) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def get_groups_friends(self, node): db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return if 'SessionModel' not in db.Tables: return tbs = SQLiteParser.TableSignature("SessionModel") for rec in db.ReadTableRecords(tbs, self.extractDeleted, True): try: if canceller.IsCancellationRequested: return # 群 if "`sessionType`" in rec and rec["`sessionType`"].Value == 3: group = model_im.Chatroom() group.source = node.AbsolutePath if rec.Deleted == DeletedState.Deleted: group.deleted = 1 group.type = 1 if "`loadName`" in rec and ( not rec["`loadName`"].IsDBNull): group.account_id = rec["`loadName`"].Value if "`sessionAvatar`" in rec and ( not rec["`sessionAvatar`"].IsDBNull): group.photo = rec["`sessionAvatar`"].Value if "`sessionNickName`" in rec and ( not rec["`sessionNickName`"].IsDBNull): group.name = rec["`sessionNickName`"].Value if "`sessionId`" in rec and ( not rec["`sessionId`"].IsDBNull): group.chatroom_id = rec["`sessionId`"].Value if group.chatroom_id and group.name: self.group_list[group.chatroom_id] = group.name if group.account_id and group.chatroom_id: self.blued.db_insert_table_chatroom(group) # 好友 elif "`sessionType`" in rec and rec["`sessionType`"].Value == 2: friend = model_im.Friend() friend.source = node.AbsolutePath friend.type = 1 if "`loadName`" in rec and ( not rec["`loadName`"].IsDBNull): friend.account_id = rec["`loadName`"].Value if "`sessionAvatar`" in rec and ( not rec["`sessionAvatar`"].IsDBNull): friend.photo = rec["`sessionAvatar`"].Value if "`sessionNickName`" in rec and ( not rec["`sessionNickName`"].IsDBNull): friend.nickname = rec["`sessionNickName`"].Value if "`sessionId`" in rec and ( not rec["`sessionId`"].IsDBNull): friend.friend_id = rec["`sessionId`"].Value if friend.friend_id and friend.nickname: self.friend_list[friend.friend_id] = friend.nickname if friend.account_id and friend.friend_id: self.blued.db_insert_table_friend(friend) except Exception as e: traceback.print_exc() self.blued.db_commit()
def get_recover_friends(self): contacts_node = self.root.GetByPath("/databases/wa.db") friends, groups = self.get_recover_friends_groups_id() if contacts_node is None: return db = SQLiteParser.Database.FromNode(contacts_node, canceller) if db is not None: try: if "wa_contacts" not in db.Tables: return if friends is None: return tbs = SQLiteParser.TableSignature("wa_contacts") SQLiteParser.Tools.AddSignatureToTable( tbs, "jid", SQLiteParser.FieldType.Text, SQLiteParser.FieldConstraints.NotNull) for rec in db.ReadTableDeletedRecords(tbs, False): if rec[1] in friends: friends = model_im.Friend() friends.account_id = self.account_id friends.deleted = 1 friends.friend_id = rec[1] friends.type = model_im.FRIEND_TYPE_FRIEND if rec[3]: friends.signature = rec[3] try: self.whatsapp.db_insert_table_friend(friends) except Exception as e: pass except Exception as e: pass else: if friends is not None: for i in friends: no_name_friends = model_im.Friend() no_name_friends.account_id = self.account_id no_name_friends.friend_id = i no_name_friends.type = model_im.FRIEND_TYPE_FRIEND try: self.whatsapp.db_insert_table_friend(no_name_friends) except Exception as e: pass self.whatsapp.db_commit()
def parse_account(self): '''解析账户数据''' try: userNode = self.node.Parent.GetByPath('/default.realm') if userNode is None: return userDir = userNode.PathWithMountPoint f = open(userDir, 'rb') content = f.read() f.close() user = [] for item in self.extract_json(content): try: account = model_im.Account() item = json.loads(item) userid = item["userid"] if "userid" in item else "" if userid in user: continue else: user.append(userid) picture = item["imageb"] picture = re.sub('@.*', '', picture) birthday = item["birthday"] timeArray = time.strptime(birthday, '%Y-%m-%d') timestamp = time.mktime(timeArray) birthday = int(timestamp) nickname = item["nickname"] desc = item["desc"] gender = item["gender"] account.account_id = userid account.nickname = nickname account.username = nickname account.photo = picture account.gender = 1 if gender == 0 else 2 if gender == 1 else 0 account.signature = desc account.birthday = birthday account.deleted = 0 if len(user) == 1 else 1 self.db_insert_table_account(account) friend = model_im.Friend() friend.account_id = userid friend.friend_id = userid friend.nickname = nickname friend.fullname = nickname friend.photo = picture friend.type = model_im.FRIEND_TYPE_FRIEND friend.signature = desc if userid is not None: self.friend[userid] = nickname if userid not in user: self.db_insert_table_account(account) except: traceback.print_exc() self.account_id = user[0] self.db_commit() except Exception as e: print(e)
def _generate_friend_table(self, node, account_id): friend_id = node.Name.split('.')[0] source = node.AbsolutePath friend = model_im.Friend() friend.source = source friend.account_id = account_id friend.nickname = friend.friend_id = friend_id friend.type = model_im.FRIEND_TYPE_FRIEND self.model_im_col.db_insert_table_friend(friend) self.model_im_col.db_commit()
def _generate_friend_table(self): """生成friend表的数据""" db_col = self.message_col for friend_id in self._friend_array: try: friend = model_im.Friend() friend.account_id = os.path.basename( db_col.db_path).split(".")[0] friend.friend_id = friend.nickname = friend.fullname = friend_id friend.source = db_col.db_path self.model_im_col.db_insert_table_friend(friend) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def get_groups_friends(self, node, account_id): db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return if 'sessionTable' not in db.Tables: return tbs = SQLiteParser.TableSignature("sessionTable") for rec in db.ReadTableRecords(tbs, False): try: if canceller.IsCancellationRequested: return # 群 if "sessionType" in rec and rec["sessionType"].Value == 3: group = model_im.Chatroom() group.account_id = account_id group.source = node.AbsolutePath group.type = 1 if "sessionAvatar" in rec and ( not rec["sessionAvatar"].IsDBNull): group.photo = rec["sessionAvatar"].Value if "sessionName" in rec and ( not rec["sessionName"].IsDBNull): group.name = rec["sessionName"].Value if "sessionId" in rec and (not rec["sessionId"].IsDBNull): group.chatroom_id = rec["sessionId"].Value if group.chatroom_id and group.name: self.group_list[group.chatroom_id] = group.name if group.account_id and group.chatroom_id: self.blued.db_insert_table_chatroom(group) # 好友 elif "sessionType" in rec and rec["sessionType"].Value == 2: friend = model_im.Friend() friend.account_id = account_id friend.source = node.AbsolutePath friend.type = 1 if "sessionAvatar" in rec and ( not rec["sessionAvatar"].IsDBNull): friend.photo = rec["sessionAvatar"].Value if "sessionName" in rec and ( not rec["sessionName"].IsDBNull): friend.nickname = rec["sessionName"].Value if "sessionId" in rec and (not rec["sessionId"].IsDBNull): friend.friend_id = rec["sessionId"].Value if friend.friend_id and friend.nickname: self.friend_list[friend.friend_id] = friend.nickname if friend.account_id and friend.friend_id: self.blued.db_insert_table_friend(friend) except Exception as e: pass self.blued.db_commit()
def parse_friend(self): '''解析好友数据''' try: node = self.node.Parent.GetByPath('/PrivateMessage.db') db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return ts = SQLiteParser.TableSignature('XYPMMessageUserModel') self.friend_id = [] for rec in db.ReadTableRecords(ts, self.extractDeleted, True): try: friend = model_im.Friend() if canceller.IsCancellationRequested: break if IsDBNull(rec['__objectID'].Value): continue friend.account_id = re.sub( '.*@', '', self._db_record_get_string_value(rec, 'local_user_id')) friend.friend_id = self._db_record_get_string_value( rec, 'user_id') friend.nickname = self._db_record_get_string_value( rec, 'nickname') friend.fullname = self._db_record_get_string_value( rec, 'nickname') friend.photo = re.sub( '@.*', '', self._db_record_get_string_value(rec, 'image')) isfriend = self._db_record_get_int_value(rec, 'is_friend') if isfriend == 1: self.friend_id.append(friend.friend_id) friend.type = model_im.FRIEND_TYPE_NONE if isfriend == 0 else model_im.FRIEND_TYPE_FRIEND friend.signature = self._db_record_get_string_value( rec, 'desc') follow_status = self._db_record_get_string_value( rec, 'follow_status') #还需要多测试几种关注状态 self.friend[friend.friend_id] = friend.nickname friend.deleted = rec.IsDeleted if friend.account_id is not '' and friend.friend_id is not '': self.db_insert_table_friend(friend) except: traceback.print_exc() self.db_commit() except Exception as e: print(e)
def parse(self): try: self.db_create(self.db_cache) cache_dir = self.dir + r'\Documents\RequestCache' db_dir = self.dir + r'\Library\Application Support\聚星众赢\AntHouseModel.sqlite' self.parse_db(db_dir) #设置一个未知好友作为不知道消息发送对象时的好友 friend = model_im.Friend() friend.account_id = self.uid friend.friend_id = 2 friend.nickname = '未知好友' friend.fullname = '未知好友' self.db_insert_table_friend(friend) self.parse_cache(cache_dir) models = model_im.GenerateModel(self.db_cache).get_models() return models except: traceback.print_exc()
def parse_recovery(self, aid): db_node = self.node.GetByPath('databases/{}'.format( self.account_dbs[aid])) if db_node is None: return sp = SQLiteParser.Database.FromNode(db_node) ts = SQLiteParser.TableSignature('users') SQLiteParser.Tools.AddSignatureToTable( ts, "user_id", SQLiteParser.FieldType.Int, SQLiteParser.FieldConstraints.NotNull) for rec in sp.ReadTableDeletedRecords(ts, False): f = model_im.Friend() f.account_id = aid f.friend_id = unity_c37r.try_get_rec_value(rec, 'user_id', 0) f.nickname = unity_c37r.try_get_rec_value(rec, 'name', '') f.remark = unity_c37r.try_get_rec_value(rec, 'username', '') f.signature = unity_c37r.try_get_rec_value(rec, 'description', '') f.photo = unity_c37r.try_get_rec_value(rec, 'image_url') f.deleted = 1 self.im.db_insert_table_friend(f) self.im.db_commit() ts = SQLiteParser.TableSignature('statuses') SQLiteParser.Tools.AddSignatureToTable( ts, "content", SQLiteParser.FieldType.Blob, SQLiteParser.FieldConstraints.NotNull) for rec in sp.ReadTableDeletedRecords(ts, False): feed = model_im.Feed() feed.account_id = aid feed.deleted = 1 try: feed.content = unity_c37r.try_get_rec_value(rec, 'content', '') feed.content = feed.content.decode('utf-8', 'ignore') feed.sender_id = unity_c37r.try_get_rec_value( rec, 'author_id', 0) feed.send_time = unity_c37r.try_get_rec_value( rec, 'created', 0) / 1000 feed.likecount = unity_c37r.try_get_rec_value( rec, 'favorite_count', 0) feed.rtcount = unity_c37r.try_get_rec_value( rec, 'retweet_count', 0) self.im.db_insert_table_feed(feed) except: traceback.print_exc() self.im.db_commit()
def get_friend(self, node, account_id): f_node = node.GetByPath("nim_cache.db") if f_node is None: return try: conn = SqliteByCSharp(f_node, self.cache) with conn as cmd: cmd.CommandText = ''' select uinfo.account,uinfo.name,uinfo.icon,uinfo.sign,uinfo.gender,uinfo.email, uinfo.mobile from uinfo,friend where uinfo.account = friend.account ''' reader = cmd.ExecuteReader() while reader.Read(): try: friend_id = SqliteByCSharp.GetString(reader, 0) nickname = SqliteByCSharp.GetString(reader, 1) avtar = SqliteByCSharp.GetString(reader, 2) sign = SqliteByCSharp.GetString(reader, 3) gender = SqliteByCSharp.GetInt64(reader, 4) email = SqliteByCSharp.GetString(reader, 5) phone = SqliteByCSharp.GetString(reader, 6) self.friend_list[friend_id] = nickname friend = model_im.Friend() friend.source = f_node.AbsolutePath friend.account_id = account_id friend.friend_id = friend_id friend.nickname = nickname friend.photo = avtar friend.telephone = phone friend.signature = sign friend.email = email friend.type = model_im.FRIEND_TYPE_FRIEND if friend.account_id and friend.friend_id: self.bulletMessage.db_insert_table_friend(friend) except Exception as e: print(e) except Exception as e: print(e) self.bulletMessage.db_commit()
def decode_recover_friend(self): table_name = self.table_name["profilecache"] if not self.recovering_helper.is_valid(): return ts = self.recovering_helper.fetch_table(table_name, { "nsp_data": "Text", }) for rec in self.recovering_helper.read_deleted_record(ts): if canceller.IsCancellationRequested: return try: friend_info = json.loads(rec["nsp_data"].Value) if friend_info.get("isManuallyAdded", None) is None: continue friend = model_im.Friend() friend.source = self.checking_col.db_path friend.account_id = self.using_account.account_id friend_type, friend.friend_id = friend_info["mri"].split( ":", 1) if friend.account_id == friend.friend_id: continue if friend_type not in ("4", "8"): continue friend.signature = friend_info.get("mood", None) friend.gender = self.__convert_gender( friend_info.get("gender", 0)) friend.nickname = friend_info.get("displayNameOverride", None) friend.telephone = self.__choose_phone_number( friend_info.get("phones", [])) friend.photo = friend_info.get("thumbUrl", None) if friend_type == "8": friend.type = model_im.FRIEND_TYPE_FRIEND friend.birthday = self._handle_birthday( friend_info.get("birthday", None)) if friend_info.get("city") or friend_info.get("country"): friend.address = friend_info.get( "city", "") + " " + friend_info.get("country", "") self.model_im_col.db_insert_table_friend(friend) except Exception as e: pass self.model_im_col.db_commit()
def parse_feed_member(self): '''解析动态成员数据''' try: node = self.node.Parent.GetByPath('/ExploreFeed.db') db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return ts = SQLiteParser.TableSignature('XYPHUser') self.id2userid = {} for rec in db.ReadTableRecords(ts, self.extractDeleted, True): try: friend = model_im.Friend() if canceller.IsCancellationRequested: break if IsDBNull(rec['__objectID'].Value): continue friend.account_id = self.account_id id = self._db_record_get_string_value(rec, '__objectID') if IsDBNull(rec['__objectID'].Value): continue friend.friend_id = self._db_record_get_string_value( rec, 'userid') if friend.friend_id is "": continue self.id2userid[id] = friend.friend_id friend.nickname = self._db_record_get_string_value( rec, 'nickname') friend.fullname = self._db_record_get_string_value( rec, 'nickname') friend.photo = re.sub( '@.*', '', self._db_record_get_string_value(rec, 'images')) isfriend = 1 if friend.friend_id in self.friend_id else 0 friend.type = model_im.FRIEND_TYPE_NONE if isfriend == 0 else model_im.FRIEND_TYPE_FRIEND self.friend[friend.friend_id] = friend.nickname friend.deleted = rec.IsDeleted self.db_insert_table_friend(friend) except: traceback.print_exc() self.db_commit() except Exception as e: print(e)
def _generate_friend_table(self): chat_db = self._search_file_simple("chat-db$") if not chat_db: return Friend.connect(chat_db) for member in Friend.objects.all: try: friend = model_im.Friend() friend.account_id = self.master_account.account_id friend.friend_id = member.user_id if friend.friend_id != "": friend.type = model_im.FRIEND_TYPE_SHOP friend.fullname = friend.nickname = member.nickname friend.photo = member.photo friend.deleted = member.deleted friend.source = member.source_path self.model_im_col.db_insert_table_friend(friend) except Exception as e: self.logger.error() self.model_im_col.db_commit()