-
-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add West Northamptonshire council, UK
- Loading branch information
Showing
4 changed files
with
93 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
54 changes: 54 additions & 0 deletions
54
...onents/waste_collection_schedule/waste_collection_schedule/source/westnorthants_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,54 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "West Northamptonshire council" | ||
DESCRIPTION = "Source for West Northamptonshire council." | ||
URL = "https://www.westnorthants.gov.uk/" | ||
TEST_CASES = { | ||
"28058314": {"uprn": 28058314}, | ||
"15049111": {"uprn": "15049111"}, | ||
} | ||
|
||
|
||
ICON_MAP = { | ||
"refuse": "mdi:trash-can", | ||
"food": "mdi:food", | ||
"garden": "mdi:recycle", | ||
"recycling": "mdi:package-variant", | ||
"recycling_boxes": "mdi:package-variant", | ||
"sacks": "mdi:sack", | ||
} | ||
|
||
|
||
API_URL = ( | ||
"https://api.westnorthants.digital/openapi/v1/unified-waste-collections/{uprn}" | ||
) | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn: str | int): | ||
self._uprn: str | int = uprn | ||
|
||
def fetch(self): | ||
# Get variables for workings | ||
response = requests.get( | ||
API_URL.format(uprn=self._uprn), | ||
) | ||
response.raise_for_status() | ||
data = response.json() | ||
|
||
entries = [] | ||
|
||
for collection in data["collectionItems"]: | ||
day = datetime.strptime(collection["date"], "%Y-%m-%d").date() | ||
entries.append( | ||
Collection( | ||
t=collection["type"], | ||
date=day, | ||
icon=ICON_MAP.get(collection["type"]), | ||
) | ||
) | ||
|
||
return sorted(entries, key=lambda x: x.date) |
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,37 @@ | ||
# West Northamptonshire council | ||
|
||
Support for schedules provided by [West Northamptonshire council](https://www.northnorthants.gov.uk/), serving West Northamptonshire council. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: westnorthants_gov_uk | ||
args: | ||
uprn: "UPRN" | ||
|
||
``` | ||
### Configuration Variables | ||
**uprn** | ||
*(String | Integer) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: westnorthants_gov_uk | ||
args: | ||
uprn: "28058314" | ||
|
||
``` | ||
## How to get the source argument | ||
An easy way to discover your Unique Property Reference Number (UPRN) is by going to <https://www.findmyaddress.co.uk/> and entering in your address details. | ||
Or by inspection the webtraffic of your browser while filling out the form you will see a request to <https://api.westnorthants.digital/openapi/v1/unified-waste-collections/28058314> where `28058314` is your UPRN. |
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