Unified IP model
| 36 | |
| 37 | |
| 38 | class IpInfoModel(BaseModel): |
| 39 | """Unified IP model""" |
| 40 | |
| 41 | ip: str = Field(title="ip") |
| 42 | port: int = Field(title="port") |
| 43 | user: str = Field(title="Username for IP proxy authentication") |
| 44 | protocol: str = Field(default="https://", title="Protocol for proxy IP") |
| 45 | password: str = Field(title="Password for IP proxy authentication user") |
| 46 | expired_time_ts: Optional[int] = Field(default=None, title="IP expiration time") |
| 47 | |
| 48 | def is_expired(self, buffer_seconds: int = 30) -> bool: |
| 49 | """ |
| 50 | Check if proxy IP has expired |
| 51 | Args: |
| 52 | buffer_seconds: Buffer time (seconds), how many seconds ahead to consider expired to avoid critical time request failures |
| 53 | Returns: |
| 54 | bool: True means expired or about to expire, False means still valid |
| 55 | """ |
| 56 | if self.expired_time_ts is None: |
| 57 | return False |
| 58 | current_ts = int(time.time()) |
| 59 | return current_ts >= (self.expired_time_ts - buffer_seconds) |