Added new version of the function, so there is a choice of grep or sed. Added a Home Assistant sensor setup config.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# Using grep
|
||||
function costco-fuel-price {
|
||||
## Get website data with curl
|
||||
## Change Store location to closest location
|
||||
costco_gateshead_site=$(curl -s https://www.costco.co.uk/store-finder/Gateshead)
|
||||
|
||||
## Grep text from website for different fuel
|
||||
costco_diesel=$(echo $costco_gateshead_site | grep -oP '"gas-title">Premium Diesel</span></br> <span class="gas-price">\K.*' | grep -oE '^.{5}')
|
||||
costco_premium_unleaded=$(echo $costco_gateshead_site | grep -oP '"gas-title">Premium Unleaded Petrol</span></br> <span class="gas-price">\K.*' | grep -oE '^.{5}')
|
||||
costco_unleaded=$(echo $costco_gateshead_site | grep -oP '"gas-title">Unleaded Petrol</span></br> <span class="gas-price">\K.*' | grep -oE '^.{5}')
|
||||
|
||||
## Print fuel prices
|
||||
echo "Premium Diesel - $costco_diesel p"
|
||||
echo "Premium Unleaded - $costco_premium_unleaded p"
|
||||
echo "Unleaded - $costco_unleaded p"
|
||||
}
|
||||
|
||||
# Using sed
|
||||
function costco-fuel-price {
|
||||
# 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}' )
|
||||
|
||||
|
||||
echo "Premium Diesel - $costco_diesel p"
|
||||
echo "Premium Unleaded - $costco_premium_unleaded p"
|
||||
echo "Unleaded - $costco_unleaded p"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
## Costco Fuel Price function
|
||||
|
||||
A function that can be added as a alias in linux to show the fuel prices for Costco.
|
||||
|
||||
There are two different versions of the function, one uses grep to parse the html and the other used sed
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
## Get website data with curl
|
||||
## Change Store location to closest location
|
||||
costco_gateshead_site=$(curl -s https://www.costco.co.uk/store-finder/Gateshead)
|
||||
|
||||
## Grep text from website for different fuel
|
||||
costco_diesel=$(echo $costco_gateshead_site | grep -oP '"gas-title">Premium Diesel</span></br> <span class="gas-price">\K.*' | grep -oE '^.{5}')
|
||||
costco_premium_unleaded=$(echo $costco_gateshead_site | grep -oP '"gas-title">Premium Unleaded Petrol</span></br> <span class="gas-price">\K.*' | grep -oE '^.{5}')
|
||||
costco_unleaded=$(echo $costco_gateshead_site | grep -oP '"gas-title">Unleaded Petrol</span></br> <span class="gas-price">\K.*' | grep -oE '^.{5}')
|
||||
|
||||
## Print fuel prices
|
||||
# echo "Premium Diesel - $costco_diesel p"
|
||||
# echo "Premium Unleaded - $costco_premium_unleaded p"
|
||||
# echo "Unleaded - $costco_unleaded p"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Set the variables
|
||||
title="Costco UK Fuel Prices"
|
||||
|
||||
|
||||
# Generate the HTML output
|
||||
cat <<EOF > ./index.html
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>${title}</h1>
|
||||
<p></P>
|
||||
<h3>Premium Diesel</h3>
|
||||
<p>${costco_diesel}p</p>
|
||||
<p></p>
|
||||
<h3>Premium Unleaded</h3>
|
||||
<p>${costco_premium_unleaded}p</p>
|
||||
<p></p>
|
||||
<h3>Unleaded</h3>
|
||||
<p>${costco_unleaded}p</p>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user