From 95d7f63d76845c8d0f712efae54ac4aceb7a70da Mon Sep 17 00:00:00 2001 From: Phil Date: Fri, 16 Dec 2022 18:38:17 +0000 Subject: [PATCH] Added files --- README.md | 6 +++++ function | 16 +++++++++++++ function_export_to_site.sh | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 function create mode 100755 function_export_to_site.sh diff --git a/README.md b/README.md index 3db25ec..258ccd8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # Costco_Fuel_Checker +A script ot scrape the costco website to check for a fuel price. + +The function_export_to_site.sh script will export the price to a HTML site. + +The Function script can be added into a .bash_aliases for looking up in a terminal. + diff --git a/function b/function new file mode 100644 index 0000000..0883694 --- /dev/null +++ b/function @@ -0,0 +1,16 @@ +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
\K.*' | grep -oE '^.{5}') +costco_premium_unleaded=$(echo $costco_gateshead_site | grep -oP '"gas-title">Premium Unleaded Petrol
\K.*' | grep -oE '^.{5}') +costco_unleaded=$(echo $costco_gateshead_site | grep -oP '"gas-title">Unleaded Petrol
\K.*' | grep -oE '^.{5}') + +## Print fuel prices +echo "Premium Diesel - $costco_diesel p" +echo "Premium Unleaded - $premium_unleaded p" +echo "Unleaded - $costco_unleaded p" +} + diff --git a/function_export_to_site.sh b/function_export_to_site.sh new file mode 100755 index 0000000..3f6fc90 --- /dev/null +++ b/function_export_to_site.sh @@ -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
\K.*' | grep -oE '^.{5}') +costco_premium_unleaded=$(echo $costco_gateshead_site | grep -oP '"gas-title">Premium Unleaded Petrol
\K.*' | grep -oE '^.{5}') +costco_unleaded=$(echo $costco_gateshead_site | grep -oP '"gas-title">Unleaded Petrol
\K.*' | grep -oE '^.{5}') + +## Print fuel prices +# echo "Premium Diesel - $costco_diesel p" +# echo "Premium Unleaded - $premium_unleaded p" +# echo "Unleaded - $costco_unleaded p" + + + + + + +# Set the variables +title="Costco UK Fuel Prices" + + +# Generate the HTML output +cat < ./index.html + + + +${title} + + +

${title}

+

+

Premium Diesel

+

${costco_diesel}p

+

+

Premium Unleaded

+

${premium_unleaded}p

+

+

Unleaded

+

${costco_unleaded}p

+ + +EOF +