Skip to content

Commit

Permalink
Add domain and logo.dev url util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shri committed Aug 27, 2024
1 parent 2f33005 commit 700ec1a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/lib/utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 700ec1a

Please sign in to comment.