increase GIF limit in search_tenor and optimize image retrieval in get_message
All checks were successful
Build and Deploy Docker Container / build-and-deploy (push) Successful in 3m12s

This commit is contained in:
2025-09-23 15:26:51 +02:00
parent 145a8be442
commit 043dd05304

12
main.py
View File

@@ -65,12 +65,12 @@ def search_tenor(search_term: str = "420") -> list:
logging.warning("TENOR_API_KEY not set") logging.warning("TENOR_API_KEY not set")
return [] return []
lmt = 8 lmt = 24
ckey = "thc-time" ckey = "thc-time"
url = f"https://tenor.googleapis.com/v2/search?q={search_term}&key={api_key}&client_key={ckey}&limit={lmt}" url = f"https://tenor.googleapis.com/v2/search?q={search_term}&key={api_key}&client_key={ckey}&limit={lmt}"
# get the top 8 GIFs for the search term # get the top n GIFs for the search term
try: try:
response = requests.get(url, timeout=10) response = requests.get(url, timeout=10)
response.raise_for_status() response.raise_for_status()
@@ -90,12 +90,8 @@ def get_message(type: str) -> dict[str, int]:
msg = messages["unknown"] msg = messages["unknown"]
if type in messages: if type in messages:
msg = messages[type] msg = messages[type]
if type == "notification": if type in ["halftime", "notification"]:
img = get_tenor_img() msg["image"] = {"url": get_tenor_img()}
else:
img = get_tenor_img(search_term=type)
if img:
msg["image"] = {"url": img}
return msg return msg