Use gandi API to get domain renewal dates

Closes: #134
This commit is contained in:
Edward Betts 2024-03-27 17:47:25 +00:00
parent 1e90df76dd
commit 422cd8aa9d
3 changed files with 44 additions and 0 deletions

View file

@ -18,6 +18,7 @@ import agenda.uk_holiday
import agenda.waste_schedule
from agenda import gwr
config = __import__("config.default", fromlist=[""])
@ -107,6 +108,20 @@ def update_thespacedevs() -> None:
print(f"took {time_taken:.1f} seconds")
def update_gandi() -> None:
"""Retrieve list of domains from gandi.net."""
url = "https://api.gandi.net/v5/domain/domains"
headers = {"authorization": "Bearer " + config.GANDI_TOKEN}
filename = os.path.join(config.DATA_DIR, "gandi_domains.json")
r = requests.request("GET", url, headers=headers)
items = r.json()
assert isinstance(items, list)
assert all(item["fqdn"] and item["dates"]["registry_ends_at"] for item in items)
with open(filename, "w") as out:
out.write(r.text)
def main() -> None:
"""Update caches."""
now = datetime.now()