MCPcopy Index your code
hub / github.com/NanmiCoder/MediaCrawler / IpInfoModel

Class IpInfoModel

proxy/types.py:38–59  ·  view source on GitHub ↗

Unified IP model

Source from the content-addressed store, hash-verified

36
37
38class 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)

Callers 6

get_proxyMethod · 0.90
get_proxyMethod · 0.90
get_proxyMethod · 0.90
get_proxyMethod · 0.85
load_all_ipMethod · 0.85

Calls 1

FieldFunction · 0.85

Tested by 1