def parse_search(self, ac): db_node = self.node.GetByPath('Library/edge_compute.db') if db_node is None: return path = unity_c37r.check_sqlite_maturity(db_node, self.cache) conn = unity_c37r.create_connection(path) cmd = sql.SQLiteCommand(conn) cmd.CommandText = ''' select args,create_time from usertrack where owner_id = {} and page_name = 'Page_SearchItemList' '''.format(ac.uid) reader = cmd.ExecuteReader() while reader.Read(): if canceller.IsCancellationRequested: cmd.Dispose() conn.Close() self.im.db_close() raise IOError('E') s = model_im.Search() s.account_id = ac.uid m_str = unity_c37r.c_sharp_get_string(reader, 0) try: #s.key = re.search('keyword=(.*?),', m_str, re.I | re.M).group(1) match = re.search('keyword=(.*?),', m_str, re.I | re.M) if match is None: continue s.key = match.group(1) except: self.log.m_err('error string:{}'.format(m_str)) continue s.create_time = unity_c37r.c_sharp_get_long(reader, 1) / 1000 self.im.db_insert_table_search(s) self.im.db_commit() cmd.Dispose() conn.Close()
def _generate_search_table(self, file_path): """ 搜索记录是存储在一个plist文件里面的 :param file_path: 搜索记录文件的地址 :return: """ if not file_path: return root = Utils.open_plist(file_path) nodes = list(root["$objects"]) for node in nodes: if hasattr(node, "Content"): key_word = getattr(node, "Content", None) if key_word == "$null": continue s = model_im.Search() s.account_id = self.using_account.account_id s.key = key_word s.source = file_path self.model_im_col.db_insert_table_search(s) self.model_im_col.db_commit() return
def parse_Search(self, table_name): ''' # 5A249183-668C-4CC0-B983-C0A7EA2E657F # \Library\Application Support\PrivateStore\P_u423af962f1456db6cba8465cf82bb91b\Search Data # \SearchData.sqlite ZRECENTSEARCHKEYWORD RecNo FieldName SQLType Size Precision PKDisplay DefaultValue NotNull NotNullConflictClause Unique UniqueConflictClause CollateValue FKDisplay 1 Z_PK INTEGER 2 Z_ENT INTEGER 3 Z_OPT INTEGER 4 ZIDX INTEGER 5 ZTYPE INTEGER 6 ZTIME TIMESTAMP 7 ZSEARCHKEYWORD VARCHAR self.account_id = None # 账号ID[TEXT] self.key = None # 搜索关键字[TEXT] self.create_time = None # 搜索时间[INT] ''' for rec in self._read_table(table_name): try: if self._is_empty(rec, 'ZSEARCHKEYWORD') or self._is_duplicate( rec, 'Z_PK'): continue search = model_im.Search() search.account_id = self.cur_account_id search.key = rec['ZSEARCHKEYWORD'].Value search.source = self.cur_db_source search.deleted = 1 if rec.IsDeleted else 0 search.insert_db(self.csm) except: exc() self.csm.db_commit()
def _generate_search_table(self, search_list): for key in search_list: try: search = model_im.Search() search.key = key search.account_id = self.master_account.account_id self.model_im_col.db_insert_table_search(search) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def _get_search_table(self): with self.icq_db_col as db_col: sql = """SELECT _id, KEY_WORD FROM SEARCH_QUERY_PROMT""" db_col.execute_sql(sql) while db_col.has_rest(): search = model_im.Search() search.key = db_col.get_string(1) search.source = self.icq_data_path self.model_im_col.db_insert_table_search(search) self.model_im_col.db_commit()
def _get_search_table(self): with self.jd_db_col as db_col: sql = """SELECT word, search_time FROM search_history""" db_col.execute_sql(sql) while db_col.has_rest(): search = model_im.Search() search.key = db_col.get_string(0) search.create_time = self.__convert_timestamp(db_col.get_int64(1)) search.source = self.jd_db_path self.model_im_col.db_insert_table_search(search) self.model_im_col.db_commit()
def _add_search_record(self, search_file): search_keys = self._read_search_records(search_file) for key in search_keys: try: search = model_im.Search() search.key = key.Value search.source = search_file.PathWithMountPoint self.model_im_col.db_insert_table_search(search) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def _generate_search_table(self): search_log_by_code = self._search_file("searchFlightByCode.txt$") if not search_log_by_code: return file_data = PlistHelper.ReadPlist(search_log_by_code) if file_data is None: return for d in file_data: try: search = model_im.Search() key = d['flightNo'] search.key = key search.account_id = self.master_account.account_id self.model_im_col.db_insert_table_search(search) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def decode_recover_search(self): if not self.recover_helper.is_valid(): return ts = self.recover_helper.fetch_table("SEARCH_QUERY_PROMT", { "KEY_WORD": "Text", }) for rec in self.recover_helper.read_deleted_record(ts): if canceller.IsCancellationRequested: return try: search = model_im.Search() search.key = rec["KEY_WORD"].Value search.source = self.icq_data_path self.model_im_col.db_insert_table_search(search) except Exception as e: print("error happen", e) self.model_im_col.db_commit()
def _generate_search_table(self): """添加search记录""" db_col = self.soul_app_col table = db_col.get_table( "search_record_post", { "_id": [FieldType.Text, FieldConstraints.NotNull], "ts": [FieldType.Int, FieldConstraints.NotNull], }) for record in db_col.read_records(table): try: s = model_im.Search() s.key = record['_id'].Value s.create_time = TimeHelper.str_to_ts( record['ts'].Value, _format="%Y-%m-%d %H:%M:%S") s.deleted = 1 if record.IsDeleted else 0 s.source = db_col.db_path self.model_im_col.db_insert_table_search(s) except Exception as e: self.logger.error() self.model_im_col.db_commit()
def decode_recover_search(self): node = self.root.GetByPath("databases/jd.db") if node is None: return db = SQLiteParser.Database.FromNode(node, canceller) if db is None: return table = 'search_history' ts = SQLiteParser.TableSignature(table) for rec in db.ReadTableDeletedRecords(ts, False): if canceller.IsCancellationRequested: return try: search = model_im.Search() search.key = rec["word"].Value search.create_time = self.__convert_timestamp(rec["search_time"].Value) search.source = self.jd_db_path self.model_im_col.db_insert_table_search(search) except Exception as e: print("error happen", e) self.model_im_col.db_commit()
def get_searchs(self): if self.user is None: return dbPath = self.root.GetByPath('../../../Documents/APGlobalSearch/' + self.md5_encode(self.user)[8:24] + '.db') db = SQLiteParser.Database.FromNode(dbPath) if db is None: return if 'global_search_recent_data' in db.Tables: ts = SQLiteParser.TableSignature('global_search_recent_data') SQLiteParser.Tools.AddSignatureToTable(ts, 'keyword', SQLiteParser.FieldType.Text, SQLiteParser.FieldConstraints.NotNull) for rec in db.ReadTableRecords(ts, self.extract_deleted): search = model_im.Search() search.deleted = DeletedState.Intact search.source = dbPath.AbsolutePath search.account_id = self.user search.key = rec['keyword'].Value search.create_time = rec['timeStamp'].Value self.im.db_insert_table_search(search) self.im.db_commit()
def parse_search(self): '''解析搜索记录''' feedNode = self.node.Parent.GetByPath('/Search') try: db = SQLiteParser.Database.FromNode(feedNode, canceller) if db is None: return ts = SQLiteParser.TableSignature('XYPHRecentSearchItem') for rec in db.ReadTableRecords(ts, self.extractDeleted, True): try: search = model_im.Search() search.account_id = self.account_id if IsDBNull(rec['__objectID'].Value): continue search.key = self._db_record_get_string_value(rec, 'name') search.create_time = self._get_timestamp( self._db_record_get_string_value(rec, 'time')) search.deleted = rec.IsDeleted self.db_insert_table_search(search) except: traceback.print_exc() self.db_commit() except Exception as e: print(e)