Skip to content

Commit

Permalink
Hinting fixes, FrugalFeeds compatability, hyperlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
tj-dodd committed Jul 3, 2024
1 parent ded42c3 commit 75fdb5f
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions uqcsbot/dominos_coupons.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ async def dominoscoupons(
Returns a list of dominos coupons
"""

website_urls: Dict[str, str] = {
"couponese": COUPONESE_DOMINOS_URL,
"frugalfeeds": FRUGAL_FEEDS_DOMINOS_URL,
"both": FRUGAL_FEEDS_DOMINOS_URL,
}

if number_of_coupons < 1 or number_of_coupons > MAX_COUPONS:
await interaction.response.send_message(
content=f"You can't have that many coupons. Try a number between 1 and {MAX_COUPONS}.",
Expand Down Expand Up @@ -131,15 +125,28 @@ async def dominoscoupons(
return

if not coupons:
await interaction.edit_original_response(
content=f"Could not find any coupons matching the given arguments from {source}."
)
if source == "both":
content_str = "Could not find any coupons matching the given arguments from both websites."
else:
content_str = f"Could not find any coupons matching the given arguments from {source}. You can try changing the website through the `source` command."
await interaction.edit_original_response(content=content_str)
return

if source == "both":
description_string = f"Sourced from [FrugalFeeds]({COUPONESE_DOMINOS_URL}) and [Couponese]({FRUGAL_FEEDS_DOMINOS_URL})"
elif source == "couponese":
description_string = f"Sourced from [Couponese]({COUPONESE_DOMINOS_URL})"
else:
description_string = (
f"Sourced from [FrugalFeeds]({FRUGAL_FEEDS_DOMINOS_URL})"
)

if keywords:
description_string += f"\nKeywords: *{keywords}*"

embed = discord.Embed(
title="Domino's Coupons",
url=(website_urls.get(source)),
description=f"Keywords: *{keywords}*" if keywords else None,
description=description_string,
timestamp=datetime.now(),
)
for coupon in coupons:
Expand Down Expand Up @@ -263,6 +270,12 @@ def _get_coupons_from_page(source: str) -> List[Coupon]:
description: str = description_container.get_text(strip=True)
code: str = code_container.get_text(strip=True)

temp_code: str = code.replace(",", "")
if not temp_code.isdigit():
continue

code = code.replace(",", " ")

if url == FRUGAL_FEEDS_DOMINOS_URL:
date_values: List[str] = expiry_date_str.split()
try:
Expand Down

0 comments on commit 75fdb5f

Please sign in to comment.