refactor ipfy source

This commit is contained in:
Dmitry Belyaev 2024-02-20 23:49:31 +03:00
parent 6949baf12e
commit 8a1ba06c88
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
1 changed files with 7 additions and 9 deletions

View File

@ -2,20 +2,18 @@ import httpx
from pddnsc.base import BaseSourceProvider
# https://www.ipify.org/
class IPIFYSource(BaseSourceProvider):
async def fetch_v4(self) -> str:
async with httpx.AsyncClient(transport=self.ipv4t) as client:
response = await client.get("https://api4.ipify.org/?format=json")
if response.status_code == httpx.codes.OK:
data = response.json()
result = None if not isinstance(data, dict) else data.get("ip")
response = await client.get("https://api4.ipify.org")
if response.is_success:
result = response.text.strip() or None
return result
async def fetch_v6(self) -> str:
async with httpx.AsyncClient(transport=self.ipv6t) as client:
response = await client.get("https://api6.ipify.org/?format=json")
if response.status_code == httpx.codes.OK:
data = response.json()
result = None if not isinstance(data, dict) else data.get("ip")
response = await client.get("https://api6.ipify.org")
if response.is_success:
result = response.text.strip() or None
return result