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

@ -23,6 +23,7 @@ from . import (
conference,
domains,
economist,
gandi,
gwr,
hn,
holidays,
@ -38,6 +39,7 @@ from . import (
)
from .types import Event, StrDict, Trip
here = dateutil.tz.tzlocal()
# deadline to file tax return
@ -449,6 +451,7 @@ async def get_data(
events += results[key]
events += read_events_yaml(my_data, last_year, next_year)
events += subscription.get_events(os.path.join(my_data, "subscriptions.yaml"))
events += gandi.get_events(data_dir)
events += economist.publication_dates(last_week, next_year)
events += meetup.get_events(my_data)
events += hn.whoishiring(last_year, next_year)

26
agenda/gandi.py Normal file
View file

@ -0,0 +1,26 @@
"""Gandi domain renewal dates."""
import os
from .types import Event
import json
def get_events(data_dir: str) -> list[Event]:
"""Get subscription renewal dates."""
filename = os.path.join(data_dir, "gandi_domains.json")
with open(filename) as f:
items = json.load(f)
assert isinstance(items, list)
assert all(item["fqdn"] and item["dates"]["registry_ends_at"] for item in items)
return [
Event(
date=item["dates"]["registry_ends_at"],
name="domain",
title=item["fqdn"] + " renewal",
)
for item in items
]

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()