-
-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Norwich City Council source (#3631)
* Add Norwich City Coucil * reformatting --------- Co-authored-by: 5ila5 <[email protected]>
- Loading branch information
Showing
9 changed files
with
202 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
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
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
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
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
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
68 changes: 68 additions & 0 deletions
68
...m_components/waste_collection_schedule/waste_collection_schedule/source/norwich_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,68 @@ | ||
import datetime | ||
import re | ||
|
||
import requests | ||
from waste_collection_schedule import Collection | ||
|
||
TITLE = "Norwich City Council" | ||
DESCRIPTION = "Source for norwich.gov.uk" | ||
URL = "https://www.norwich.gov.uk" | ||
TEST_CASES = { | ||
"1 Stuart Road": {"uprn": "100090924499"}, | ||
} | ||
|
||
API_URL = "https://maps.norwich.gov.uk/arcgis/rest/services/MyNorwich/PropertyDetails/FeatureServer/3/query" | ||
COLLECTION_TYPES = { | ||
"waste and food waste": { | ||
"title": "Waste and Food Waste", | ||
"icon": "mdi:trash-can", | ||
}, | ||
"recycling and food waste": { | ||
"title": "Recycling and Food Waste", | ||
"icon": "mdi:recycle", | ||
}, | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn: str): | ||
self._uprn = uprn | ||
|
||
def fetch(self) -> list[Collection]: | ||
params = { | ||
"f": "json", | ||
"where": f"UPRN='{self._uprn}' or UPRN='0{self._uprn}'", | ||
"outFields": "WasteCollectionHtml", | ||
} | ||
response = requests.get(API_URL, params=params) | ||
response.raise_for_status() | ||
|
||
features = response.json()["features"] | ||
|
||
if len(features) != 1: | ||
raise Exception(f"Expected 1 feature, got {len(features)}") | ||
|
||
html = features[0]["attributes"]["WasteCollectionHtml"] | ||
|
||
date_match = re.search(r"Your next collection: <strong>(.*?)</strong>", html) | ||
if not date_match: | ||
raise Exception("No collection date found") | ||
date_str = date_match.group(1) | ||
type_match = re.search(r"We will be collecting: <strong>(.*?).</strong>", html) | ||
if not type_match: | ||
raise Exception("No collection type found") | ||
type_str = type_match.group(1) | ||
|
||
date = datetime.datetime.strptime(date_str, "%d/%m/%Y").date() | ||
|
||
type = COLLECTION_TYPES.get(type_str) or {} | ||
|
||
entries = [ | ||
Collection( | ||
date=date, | ||
t=type["title"], | ||
icon=type["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 @@ | ||
# North Norfolk District Council | ||
|
||
Support for the next collection day provided by [Norwich City Council](https://maps.norwich.gov.uk/mynorwich/), serving Norwich, UK. | ||
|
||
Note that Norwich City Council does not provide a schedule, only the next collection day. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: norwich_gov_uk | ||
args: | ||
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER | ||
``` | ||
|
||
### Configuration Variables | ||
|
||
**uprn** | ||
*(string) (required)* | ||
|
||
## Example | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: norwich_gov_uk | ||
args: | ||
uprn: "100090924499" | ||
``` | ||
|
||
## 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. |
Oops, something went wrong.