-
-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding denbighshire_gov_uk * reformatting + ./update_docu_links.py * reformatting + ./update_docu_links.py --------- Co-authored-by: Chris Imeson <[email protected]> Co-authored-by: 5ila5 <[email protected]> Co-authored-by: 5ila5 <[email protected]>
- Loading branch information
1 parent
3de0c9d
commit 71d0fe9
Showing
4 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ponents/waste_collection_schedule/waste_collection_schedule/source/denbighshire_gov_uk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import json | ||
from datetime import datetime | ||
|
||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Denbighshire County Council" | ||
DESCRIPTION = "Source for Denbighshire County Council." | ||
URL = "https://www.denbighshire.gov.uk/" | ||
TEST_CASES = { | ||
"10003928409": {"uprn": "10003928409"}, | ||
"100100183412": {"uprn": 100100183412}, | ||
} | ||
|
||
ICON_MAP = { | ||
"garden": "mdi:leaf", | ||
"food": "mdi:food", | ||
"household": "mdi:trash-can", | ||
"recycle": "mdi:recycle", | ||
} | ||
|
||
API_URL = "https://www.denbighshire.gov.uk/api/Custom/RefuseApi/GetCollectionDates" | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn: str | int): | ||
self._uprn: str | int = uprn | ||
|
||
def fetch(self): | ||
h = { | ||
"referer": "https://www.denbighshire.gov.uk/en/bins-and-recycling/bin-collections.aspx" | ||
} | ||
r = requests.get(API_URL, params={"uprn": self._uprn}, headers=h) | ||
r.raise_for_status() | ||
|
||
message = json.loads(r.json()["message"]) | ||
entries = [] | ||
print(message) | ||
for type in ["Household", "Recycling", "Food"]: | ||
date_str = message[f"{type}Date"] | ||
date = datetime.strptime(date_str, "%A %d/%m/%Y").date() | ||
|
||
icon = ICON_MAP.get(type.lower()) | ||
entries.append(Collection(date=date, t=type.lower(), icon=icon)) | ||
|
||
# garden waste is collected on the same day as household, but isn't returned in the API | ||
if type == "Household": | ||
also = "Garden" | ||
icon = ICON_MAP.get(also.lower()) | ||
entries.append(Collection(date=date, t=also.lower(), icon=icon)) | ||
|
||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Denbighshire County Council | ||
|
||
Support for schedules provided by [Denbighshire County Council](https://www.denbighshire.gov.uk/), serving Denbighshire, UK. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: denbighshire_gov_uk | ||
args: | ||
uprn: "UPRN" | ||
|
||
``` | ||
### Configuration Variables | ||
**uprn** | ||
*(String | Integer) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: denbighshire_gov_uk | ||
args: | ||
uprn: "200003177805" | ||
|
||
``` | ||
## How to get the source argument | ||
To discover your Unique Property Reference Number (UPRN), go to <https://www.findmyaddress.co.uk/> and enter your address details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters