diff --git a/src/app/lib/utils.py b/src/app/lib/utils.py new file mode 100644 index 00000000..f6ae6302 --- /dev/null +++ b/src/app/lib/utils.py @@ -0,0 +1,18 @@ +import os +from urllib.parse import urlparse + + +def get_domain(url: str) -> str: + """Extract domain from url.""" + parsed_url = urlparse(url) + return parsed_url.netloc + + +def get_logo_dev_link(url: str) -> str | None: + """Construct a logo.dev url.""" + try: + domain = get_domain(url) + logo_dev_token = os.environ["LOGO_DEV_TOKEN"] + return f"https://img.logo.dev/{domain}?token={logo_dev_token}" + except Exception: + pass