replace image
All checks were successful
Build and Deploy Docker Container / build-and-deploy (push) Successful in 2m14s
All checks were successful
Build and Deploy Docker Container / build-and-deploy (push) Successful in 2m14s
This commit is contained in:
46
main.py
46
main.py
@@ -40,49 +40,6 @@ messages = {
|
||||
}
|
||||
|
||||
|
||||
def get_tenor_img(search_term: str = "420") -> str | None:
|
||||
results = []
|
||||
try:
|
||||
results = search_tenor(search_term=search_term)
|
||||
except Exception as e:
|
||||
logging.error(f"Error fetching Tenor GIF: {e}")
|
||||
if results:
|
||||
# get a random image from the results
|
||||
r = random.choice(results)
|
||||
formats = r["media_formats"]
|
||||
# try to get the tinygif format
|
||||
tinygif = formats.get("tinygif", {}).get("url")
|
||||
if tinygif:
|
||||
return tinygif
|
||||
|
||||
|
||||
def search_tenor(search_term: str = "420") -> list:
|
||||
"""
|
||||
Fetch a random GIF URL from Tenor based on the provided slug.
|
||||
"""
|
||||
api_key = os.getenv('TENOR_API_KEY')
|
||||
if not api_key:
|
||||
logging.warning("TENOR_API_KEY not set")
|
||||
return []
|
||||
|
||||
lmt = 24
|
||||
ckey = "thc-time"
|
||||
|
||||
url = f"https://tenor.googleapis.com/v2/search?q={search_term}&key={api_key}&client_key={ckey}&limit={lmt}"
|
||||
|
||||
# get the top n GIFs for the search term
|
||||
try:
|
||||
response = requests.get(url, timeout=10)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
if data["results"]:
|
||||
return data["results"]
|
||||
return []
|
||||
except requests.RequestException as e:
|
||||
logging.error(f"Error fetching Tenor GIF: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def get_message(type: str) -> dict[str, int]:
|
||||
"""
|
||||
Get the notification message based on the type.
|
||||
@@ -91,7 +48,8 @@ def get_message(type: str) -> dict[str, int]:
|
||||
if type in messages:
|
||||
msg = messages[type]
|
||||
if type in ["halftime", "notification"]:
|
||||
msg["image"] = {"url": get_tenor_img()}
|
||||
msg["image"] = {
|
||||
"url": "https://www.freepnglogos.com/uploads/weed-leaf-png/cannabis-weed-leaf-png-clipart-images-24.png"}
|
||||
return msg
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user