Skip to content

Commit

Permalink
Merge pull request #1 from mewejo/feat/php
Browse files Browse the repository at this point in the history
PHP for real regex
  • Loading branch information
mewejo authored Feb 7, 2023
2 parents fbe25c5 + 7c90299 commit a0c337f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <property-reference-number>
./tools/refuse-collection <property-reference-number>
```

```json
Expand All @@ -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
},
```
18 changes: 18 additions & 0 deletions tools/refuse-collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/php
<?php

$propertyId = $argv[1];

$response = file_get_contents("https://www.cornwall.gov.uk/umbraco/Surface/Waste/MyCollectionDays?uprn={$propertyId}&subscribe=False");

preg_match("/Recycling(\S+\W+){2}span>(\d{2}) (\w{3})/", $response, $matches);

echo json_encode([
"recycling" => [
"next_collection" => [
"date_raw" => sprintf("%s %s", $matches[2] ?? '', $matches[3] ?? ''),
],
],
]);


13 changes: 0 additions & 13 deletions tools/refuse-collection.sh

This file was deleted.

0 comments on commit a0c337f

Please sign in to comment.