| 18 | |
| 19 | # Capture endpoint statistics from logs |
| 20 | class EndpointStatsHandler(logging.Handler): |
| 21 | def __init__(self): |
| 22 | super().__init__() |
| 23 | self.stats = defaultdict(int) |
| 24 | self.current_query = None |
| 25 | |
| 26 | def emit(self, record): |
| 27 | # Look for "Got X results from endpoint_name" messages |
| 28 | if "Got" in record.getMessage() and "results from" in record.getMessage(): |
| 29 | match = re.search(r'Got (\d+) results from (\w+)', record.getMessage()) |
| 30 | if match: |
| 31 | count = int(match.group(1)) |
| 32 | endpoint = match.group(2) |
| 33 | self.stats[endpoint] = count |
| 34 | |
| 35 | def reset(self): |
| 36 | self.stats = defaultdict(int) |
| 37 | |
| 38 | |
| 39 | async def run_query_with_stats(query: str, site: str = "all", num_results: int = 50): |
no outgoing calls