Create IP proxy pool :param ip_pool_count: Number of IPs in the pool :param enable_validate_ip: Whether to enable IP proxy validation :return:
(ip_pool_count: int, enable_validate_ip: bool)
| 196 | |
| 197 | |
| 198 | async def create_ip_pool(ip_pool_count: int, enable_validate_ip: bool) -> ProxyIpPool: |
| 199 | """ |
| 200 | Create IP proxy pool |
| 201 | :param ip_pool_count: Number of IPs in the pool |
| 202 | :param enable_validate_ip: Whether to enable IP proxy validation |
| 203 | :return: |
| 204 | """ |
| 205 | ip_provider = IpProxyProvider.get(config.IP_PROXY_PROVIDER_NAME) |
| 206 | if ip_provider is None: |
| 207 | raise ValueError( |
| 208 | f"Unknown proxy provider: '{config.IP_PROXY_PROVIDER_NAME}'. " |
| 209 | f"Valid options: {list(IpProxyProvider.keys())}" |
| 210 | ) |
| 211 | is_static = config.IP_PROXY_PROVIDER_NAME == ProviderNameEnum.STATIC_PROVIDER.value |
| 212 | pool = ProxyIpPool( |
| 213 | ip_pool_count=ip_pool_count, |
| 214 | enable_validate_ip=False if is_static else enable_validate_ip, |
| 215 | ip_provider=ip_provider, |
| 216 | ) |
| 217 | await pool.load_proxies() |
| 218 | return pool |
| 219 | |
| 220 | |
| 221 | if __name__ == "__main__": |