Skip to content

Commit

Permalink
Add parameter 'keep_tld' to function 'get_website_name'
Browse files Browse the repository at this point in the history
  • Loading branch information
Crinibus committed Nov 14, 2023
1 parent 2ce1afc commit ac9ca8a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scraper/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ def get_short_url(self) -> str:
return f"https://www.hifiklubben.dk/{id}"


def get_website_name(url: str) -> str:
def get_website_name(url: str, keep_tld=False) -> str:
stripped_url = url.removeprefix("https://").removeprefix("http://").removeprefix("www.")
domain = stripped_url.split("/")[0]

# Remove the TLD/DNS name (such as ".com")
website_name_list = domain.split(".")[:-1]
# Remove the TLD/DNS name (such as ".com") if keep_tld is false
website_name_list = domain.split(".") if keep_tld else domain.split(".")[:-1]
website_name = ".".join(website_name_list)
return website_name

Expand Down

0 comments on commit ac9ca8a

Please sign in to comment.