From 8a1ba06c88d6cff0b08a1091293ff59251d4055d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 20 Feb 2024 23:49:31 +0300 Subject: [PATCH] refactor ipfy source --- pddnsc/sources/ipfy.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pddnsc/sources/ipfy.py b/pddnsc/sources/ipfy.py index 8a06d49..63d290e 100644 --- a/pddnsc/sources/ipfy.py +++ b/pddnsc/sources/ipfy.py @@ -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