(self)
| 172 | self.total_count = 0 # 保存搜索结果总数 |
| 173 | |
| 174 | def search(self): |
| 175 | try: |
| 176 | search_cnt = 0 |
| 177 | total_search_cnt = len(self.built_in_rules) |
| 178 | for build_in in self.built_in_rules: |
| 179 | search_cnt += 1 |
| 180 | build_in = build_in.strip() |
| 181 | if not build_in: |
| 182 | continue |
| 183 | |
| 184 | curr_page = 1 |
| 185 | query = "{} {}".format(self.query, build_in) |
| 186 | results, total_count = github_search_code(query=query, per_page=self.per_page, page=curr_page) |
| 187 | logger.info("[{}/{}] page:1 keyword:{} total:{}".format(search_cnt, |
| 188 | total_search_cnt, self.query, total_count)) |
| 189 | |
| 190 | self.total_count += total_count |
| 191 | |
| 192 | # 对于根据文件来查的,应该只跑一页 |
| 193 | if "filename:" not in build_in: |
| 194 | while (total_count / 100) > curr_page and curr_page < self.max_page: |
| 195 | curr_page += 1 |
| 196 | next_results, total_count = github_search_code(query=query, per_page=self.per_page, page=curr_page) |
| 197 | logger.info("page:{} keyword:{} total:{}".format(curr_page, self.query, total_count)) |
| 198 | results.extend(next_results) |
| 199 | |
| 200 | for result in results: |
| 201 | if result not in self.results: |
| 202 | self.results.append(result) |
| 203 | except Exception as e: |
| 204 | logger.info("Error on {} {}".format(self.query, e)) |
| 205 | logger.exception(e) |
| 206 | |
| 207 | logger.info("{} search result {}".format(self.query, len(self.results))) |
| 208 | return self.results |
| 209 | |
| 210 | |
| 211 | def github_search(keyword): |
no test coverage detected