forked from mampfes/hacs_waste_collection_schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Source: Bedford Borough Council (mampfes#924)
* initial commit * test cases added * md file added, typos corrected * update_docu_links run
- Loading branch information
Showing
4 changed files
with
81 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
48 changes: 48 additions & 0 deletions
48
...m_components/waste_collection_schedule/waste_collection_schedule/source/bedford_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,48 @@ | ||
import requests | ||
import json | ||
|
||
from datetime import datetime | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Bedford Borough Council" | ||
DESCRIPTION = "Source for bradford.gov.uk services for Bedford Borough Council, UK." | ||
URL = "https://bedford.gov.uk" | ||
TEST_CASES = { | ||
"Test_001": {"uprn": "100080009302"}, | ||
"Test_002": {"uprn": "100081207036"}, | ||
"Test_003": {"uprn": 100080018481}, | ||
"Test_004": {"uprn": 100080023672}, | ||
} | ||
HEADERS = { | ||
"user-agent": "Mozilla/5.0", | ||
} | ||
ICON_MAP = { | ||
"BLACK BIN": "mdi:trash-can", | ||
"ORANGE BIN": "mdi:recycle", | ||
"GREEN BIN": "mdi:leaf", | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn): | ||
self._uprn = str(uprn).zfill(12) | ||
|
||
def fetch(self): | ||
|
||
s = requests.Session() | ||
r = s.get(f"https://bbaz-as-prod-bartecapi.azurewebsites.net/api/bincollections/residential/getbyuprn/{self._uprn}/35", headers=HEADERS) | ||
json_data = json.loads(r.text)["BinCollections"] | ||
|
||
entries = [] | ||
|
||
for day in json_data: | ||
for bin in day: | ||
entries.append( | ||
Collection( | ||
date=datetime.strptime(bin["JobScheduledStart"], "%Y-%m-%dT00:00:00").date(), | ||
t=bin["BinType"], | ||
icon=ICON_MAP.get(bin["BinType"].upper()), | ||
) | ||
) | ||
|
||
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,31 @@ | ||
# Ashfield District Council | ||
|
||
Support for schedules provided by [Bedford Borough Council](https://www.bedford.gov.uk/), serving Bedford Borough Council, UK. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: bedford_gov_uk | ||
args: | ||
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER | ||
``` | ||
### Configuration Variables | ||
**uprn**<br> | ||
*(string) (required)* | ||
#### How to find your `UPRN` | ||
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. | ||
|
||
## Example using UPRN | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: bedford_gov_uk | ||
args: | ||
uprn: 100080023672 | ||
``` |
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