From 8eae0e0929436a944424087d7771b43a0946719d Mon Sep 17 00:00:00 2001 From: Josh Bonfield Date: Sat, 21 Jan 2023 18:09:52 +0000 Subject: [PATCH 1/2] wip: rename to sh to be agnostic --- README.md | 4 ++-- tools/{refuse-collection.sh => refuse-collection} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename tools/{refuse-collection.sh => refuse-collection} (100%) diff --git a/README.md b/README.md index a3a3ec2..eab10f6 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_date' | awk '{print \"♻ \" $1 \" \" $2}'", "interval": 86400 }, ``` diff --git a/tools/refuse-collection.sh b/tools/refuse-collection similarity index 100% rename from tools/refuse-collection.sh rename to tools/refuse-collection From 7c9029922c2dd8e6046d12b588b98e063a80af45 Mon Sep 17 00:00:00 2001 From: Josh Bonfield Date: Tue, 7 Feb 2023 19:53:07 +0000 Subject: [PATCH 2/2] feat: php version with proper regex support --- README.md | 2 +- tools/refuse-collection | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index eab10f6..b79eece 100644 --- a/README.md +++ b/README.md @@ -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 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 index 30ea9a5..3d4c21f 100755 --- a/tools/refuse-collection +++ b/tools/refuse-collection @@ -1,13 +1,18 @@ -#!/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" +#!/usr/bin/php +(\d{2}) (\w{3})/", $response, $matches); + +echo json_encode([ + "recycling" => [ + "next_collection" => [ + "date_raw" => sprintf("%s %s", $matches[2] ?? '', $matches[3] ?? ''), + ], + ], +]); -echo "{\"recycling_date\": \"$recycling_date\"}" | jq