42 lines
1.6 KiB
Bash
42 lines
1.6 KiB
Bash
#!/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")
|
|
|
|
# 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")
|
|
|
|
# Extract the date from the found date and time
|
|
event_date=$(echo "$found_date_time" | awk -F' / ' '{print $1}')
|
|
|
|
# Extract the time from the found date and time
|
|
event_time=$(echo "$found_date_time" | awk -F' / ' '{print $2}')
|
|
# 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
|