diff --git a/README.md b/README.md index a3a3ec2..b79eece 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ To find your UPRN, visit the [Cornwall Council website](https://www.cornwall.gov Output is returned as JSON. ```bash -./tools/refuse-collection.sh +./tools/refuse-collection ``` ```json @@ -27,7 +27,7 @@ I am using this with Waybar to show the recyling date in my system tray. For exa ```json "custom/recycling": { - "exec": "~/cornwall-council/tools/refuse-collection.sh 000000000000 | jq -r '.recycling_date' | awk '{print \"♻ \" $1 \" \" $2}'", + "exec": "~/cornwall-council/tools/refuse-collection 000000000000 | jq -r '.recycling.next_collection.date_raw' | awk '{print \"♻ \" $1 \" \" $2}'", "interval": 86400 }, ``` diff --git a/tools/refuse-collection b/tools/refuse-collection new file mode 100755 index 0000000..3d4c21f --- /dev/null +++ b/tools/refuse-collection @@ -0,0 +1,18 @@ +#!/usr/bin/php +(\d{2}) (\w{3})/", $response, $matches); + +echo json_encode([ + "recycling" => [ + "next_collection" => [ + "date_raw" => sprintf("%s %s", $matches[2] ?? '', $matches[3] ?? ''), + ], + ], +]); + + diff --git a/tools/refuse-collection.sh b/tools/refuse-collection.sh deleted file mode 100755 index 30ea9a5..0000000 --- a/tools/refuse-collection.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -recycling_pattern="([0-9]{1,2} [A-Z][a-z]{2})" -url="https://www.cornwall.gov.uk/umbraco/Surface/Waste/MyCollectionDays?uprn={$1}&subscribe=False" - -response=$(curl --silent $url) - -if [[ $response =~ $recycling_pattern ]] -then - recycling_date="${BASH_REMATCH[1]}" -fi - -echo "{\"recycling_date\": \"$recycling_date\"}" | jq -