webfinger/webfinger/io.py
2022-12-10 19:34:30 -06:00

19 lines
467 B
Python

import json
from os import environ as env
from pathlib import Path
def get_document(resource: str) -> dict | None:
# Get a filename for the resource document.
dir = env.get("RESOURCE_DIR") or "resource"
filename = f"{dir}/{resource}.json"
# Check that the file exists.
path = Path(filename)
if not path:
return None
# Open the file and load the JSON as a dictionary.
with open(filename, "r") as file:
data: dict = json.loads(file.read())
return data