Costco_Fuel_Checker/HomeAssistant/fetch_costco_prices.sh

17 lines
890 B
Bash
Raw Normal View History

#!/bin/bash
# Get website data with curl
costco_gateshead_site=$(curl -s https://www.costco.co.uk/store-finder/Gateshead)
# Extract text for different fuel prices using sed
costco_diesel=$(echo $costco_gateshead_site | sed -n 's/.*"gas-title">Premium Diesel<\/span><\/br> <span class="gas-price">\([^<]\{5\}\).*/\1/p' | grep -oE '^.{5}' )
costco_premium_unleaded=$(echo $costco_gateshead_site | sed -n 's/.*"gas-title">Premium Unleaded Petrol<\/span><\/br> <span class="gas-price">\([^<]\{5\}\).*/\1/p' | grep -oE '^.{5}' )
costco_unleaded=$(echo $costco_gateshead_site | sed -n 's/.*"gas-title">Unleaded Petrol<\/span><\/br> <span class="gas-price">\([^<]\{5\}\).*/\1/p' | grep -oE '^.{5}' )
# Print fuel prices in JSON format for Home Assistant
echo "{\"premium_diesel\": \"$costco_diesel\", \"premium_unleaded\": \"$costco_premium_unleaded\", \"unleaded\": \"$costco_unleaded\"}"