get a batch of random proxies firstly try to get proxies with max score, if not enough, get proxies by rank (score from high to low) if none exists, raise error :param count: number of proxies to return :return: list of proxies
(self, count, redis_key=REDIS_KEY, proxy_score_min=PROXY_SCORE_MIN, proxy_score_max=PROXY_SCORE_MAX)
| 71 | raise PoolEmptyException |
| 72 | |
| 73 | def randoms(self, count, redis_key=REDIS_KEY, proxy_score_min=PROXY_SCORE_MIN, proxy_score_max=PROXY_SCORE_MAX) -> List[Proxy]: |
| 74 | """ |
| 75 | get a batch of random proxies |
| 76 | firstly try to get proxies with max score, |
| 77 | if not enough, get proxies by rank (score from high to low) |
| 78 | if none exists, raise error |
| 79 | :param count: number of proxies to return |
| 80 | :return: list of proxies |
| 81 | """ |
| 82 | # try to get proxies with max score first |
| 83 | proxies = self.db.zrangebyscore( |
| 84 | redis_key, proxy_score_max, proxy_score_max) |
| 85 | if len(proxies) < count: |
| 86 | # not enough max-score proxies, fall back to all proxies by rank |
| 87 | proxies = self.db.zrevrangebyscore( |
| 88 | redis_key, proxy_score_max, proxy_score_min) |
| 89 | if not proxies: |
| 90 | raise PoolEmptyException |
| 91 | count = min(count, len(proxies)) |
| 92 | return convert_proxy_or_proxies(sample(proxies, count)) |
| 93 | |
| 94 | def decrease(self, proxy: Proxy, redis_key=REDIS_KEY, proxy_score_min=PROXY_SCORE_MIN) -> int: |
| 95 | """ |
no test coverage detected