trim() {
    local var="$*"
    # remove leading whitespace characters
    var="${var#"${var%%[![:space:]]*}"}"
    # remove trailing whitespace characters
    var="${var%"${var##*[![:space:]]}"}"   
    printf '%s' "$var"
}

# Ask user to enter the event_id here
echo 'Enter Event ID:'
read event_id
# Store into %URL%
url="https://www.rampagebots.co.uk/api/events/upcoming_battles?id=$event_id"

# Poll Rampage every 60 seconds for information
# The response from Rampage is cached for 60 seconds so changing the polling time to anything less than 60
# Won't achieve anything.

sleep_time=60

while true
do

battle= echo $(curl -LsN $url -H "Accept: application/json" -H "Content-Type: application/json" | jq -r .nextBattles > all_battles.txt)

echo "Upcoming Fights:"

battles="$(tail -n1000 all_battles.txt)"

echo "$battles"

format= $(cat all_battles.txt | sed '1d;$d' | sed 's/"//g' | sed 's/^ *//g' | tr ',' ' ' | sed 's/ *$//g' > all_battles_formatted.txt)

echo "Polling again in $sleep_time seconds"
sleep $sleep_time
done