commit c1c2172f638c7495f3c7952ef55d5f12c6bae6e4 Author: Clarth Date: Sat Jan 27 13:06:13 2024 -0500 Add ufc.sh diff --git a/ufc.sh b/ufc.sh new file mode 100644 index 0000000..a1f4c40 --- /dev/null +++ b/ufc.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Specify your Discord webhook URL +discord_webhook_url="https://discord.com/api/webhooks/" + +# Get the current date in the desired format (e.g., "Sat, Feb 3") +current_date=$(date "+%a, %b %-d") +echo $current_date + +# Specify the URL of the webpage +webpage_url="https://www.ufc.com/events" + +# Download the webpage content using curl +webpage_content=$(curl -s "$webpage_url") + + +# Specify a pattern for a date and time in the format "Sat, Feb 24 / 10:00 PM EST" +date_time_pattern="[A-Za-z]+, [A-Za-z]+ [0-9]+ / [0-9]+:[0-9]+ [APMapm]+ [A-Za-z]+" + +# Search for the date and time pattern using grep +found_date_time=$(echo "$webpage_content" | grep -m 1 -o -E "$date_time_pattern") +echo $found_date_time + +# Extract the date from the found date and time +event_date=$(echo "$found_date_time" | awk -F' / ' '{print $1}') +echo $event_date + +# Extract the time from the found date and time +event_time=$(echo "$found_date_time" | awk -F' / ' '{print $2}') +echo $event_time +# Check if the found date matches the current date +if [ "$event_date" == "$current_date" ]; then + echo "Sending Discord message for today's date and time." + + # Set the bot's username and avatar URL + bot_username="UFC BOT" + bot_avatar_url="https://i.imgur.com/B5ub4bV.png" + + # Construct the Discord message with username and avatar + discord_message='{"content":"There is a UFC fight today!\n'"$event_date"' at '"$event_time"'","username":"'"$bot_username"'","avatar_url":"'"$bot_avatar_url"'"}' + + # Send the message to Discord using curl and the webhook URL + curl -H "Content-Type: application/json" -X POST -d "$discord_message" "$discord_webhook_url" +else + echo "No match for today's date on the webpage." +fi