def __get_profile(self, sqlpath: str): """ 在文件夹里扫描profile后缀的数据,添加task信息后返回 因为profile里包含了userid并且只有一个文件,所以会优先将 profile数据获取到再进行后续数据获取 :param sqlpath: :return: """ sql = ''' select * from users where self=? ''' par = (1, ) res = self._select_data(sqlpath, sql, par) if len(res) == 0: self._logger.error("No profile in db") return eldict = res[0] if eldict.get('id') is None: self._logger.error("No profile in db") return self._userid = eldict.get('id') p_data = PROFILE(self._clientid, self.task, self.task.apptype, self._userid) phone = eldict.pop('phone') if phone is not None and phone != '': p_data.phone = self._output_format_str(phone) p_data.account = self._phone nickname = b'' if eldict.get('last_name') is not None: nickname += eldict.pop('last_name') if eldict.get('first_name') is not None: nickname += eldict.pop('first_name') if nickname == b'' and eldict.get('username') is not None: nickname += eldict.pop('username') if nickname != b'': p_data.nickname = self._output_format_str(nickname) # if len(prodata) > 0: # p_data.append_details(prodata) yield p_data
def _read_datas(self, dbpath) -> iter: """read datas from db""" try: # 下载数据成功 sql = '''SELECT * FROM msg ''' res_lines = self._select_data(dbpath, sql) if len(res_lines) == 0: return contacts_all = {} logs_all = ICHATLOG(self._clientid, self.task, self.task.apptype) for line in res_lines: if line.get('content') is None and line.get('content') == '': continue try: conversionid = line.get('conversation_id').split(':') if len(conversionid) != 0: if self._userid == '': self._userid = conversionid[-1] contact_id = conversionid[-2] contacts_all[contact_id] = 1 else: continue messagetype: EResourceType = self._resources_type.get( line['type']) sessionid = conversionid[-2] messageid = line['msg_uuid'] senderid = line['sender'] cr_time = time.strftime( '%Y-%m-%d %H:%M:%S', time.localtime(line['created_time'] / 1000)) log_one = ICHATLOG_ONE(self.task, self.task.apptype, self._userid, messagetype.value, sessionid, 1, messageid, senderid, cr_time) if messagetype == EResourceType.Picture or messagetype == EResourceType.Audio: for res_file in self._get_resources(line, messagetype): log_one.append_resource(res_file) yield res_file try: json_text = json.loads(line['content']) except Exception as err: self._logger.error( "Content data is not json, err:{}".format(err)) continue # 文字 if json_text.get('text') is not None: log_one.content = json_text.get('text') logs_all.append_innerdata(log_one) except Exception: self._logger.error( "Parse one data line from db error: {} {}".format( self.uname_str, traceback.format_exc())) if logs_all.innerdata_len > 0: yield logs_all if self._userid != '': p_data = PROFILE(self._clientid, self.task, self.task.apptype, self._userid) p_data.account = self._phone p_data.phone = self._phone yield p_data if len(contacts_all) != 0: ct_all = CONTACT(self._clientid, self.task, self.task.apptype) for ct in contacts_all: ct_one = CONTACT_ONE(self._userid, ct, self.task, self.task.apptype) ct_one.isfriend = 1 ct_one.isdeleted = 0 ct_all.append_innerdata(ct_one) yield ct_all except Exception: self._logger.error("Read datas from db error: {} {}".format( self.uname_str, traceback.format_exc()))