-
-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Source: Melton District, UK (#3339)
* initial commit * test cases updated * .md added * undo * .py added * .md added * update_docu_links
- Loading branch information
Showing
8 changed files
with
188 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
79 changes: 79 additions & 0 deletions
79
...om_components/waste_collection_schedule/waste_collection_schedule/source/melton_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,79 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Melton Borough Council" | ||
DESCRIPTION = "Source for waste collection services for Melton Borough Council, UK" | ||
URL = "https://www.melton.gov.uk/" | ||
|
||
HEADERS = {"user-agent": "Mozilla/5.0"} | ||
|
||
HOW_TO_GET_ARGUMENTS_DESCRIPTION = { | ||
"en": "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.", | ||
} | ||
|
||
PARAM_TRANSLATIONS = { | ||
"en": { | ||
"uprn": "Unique Property Reference Number (UPRN)", | ||
} | ||
} | ||
|
||
PARAM_DESCRIPTIONS = { | ||
"en": { | ||
"uprn": "Unique Property Reference Number (UPRN)", | ||
} | ||
} | ||
|
||
TEST_CASES = { | ||
"Test_001": { | ||
"uprn": "100030544791", | ||
}, | ||
"Test_002": { | ||
"uprn": 100030549260, | ||
}, | ||
"Test_003": { | ||
"uprn": "100030537000", | ||
}, | ||
} | ||
|
||
ICON_MAP = { | ||
"Refuse": "mdi:trash-can", | ||
"Recycling": "mdi:recycle", | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn: str | int): | ||
self._uprn = str(uprn) | ||
|
||
def fetch(self) -> list[Collection]: | ||
s = requests.Session() | ||
|
||
params: dict = { | ||
"id": self._uprn, | ||
"redirect": "collections", | ||
"rememberloc": "", | ||
} | ||
r = s.get( | ||
"https://my.melton.gov.uk/set-location", headers=HEADERS, params=params | ||
) | ||
r.raise_for_status | ||
soup: BeautifulSoup = BeautifulSoup(r.content, "html.parser") | ||
|
||
entries: list = [] | ||
list_items: list = soup.find_all("li", {"class": ["dark-blue", "burgundy"]}) | ||
for item in list_items: | ||
waste_type: str = item.find("h2").text | ||
waste_dates: list = item.find("strong").text.split(", and then ") | ||
for waste_date in waste_dates: | ||
entries.append( | ||
Collection( | ||
date=datetime.strptime(waste_date, "%d/%m/%Y").date(), | ||
t=waste_type, | ||
icon=ICON_MAP.get(waste_type), | ||
) | ||
) | ||
|
||
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,32 @@ | ||
# Melton Borough Council | ||
|
||
Support for schedules provided by [Melton Borough Council](https://www.melton.gov.uk/waste-and-recycling/), serving Melton District, UK. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: melton_gov_uk | ||
args: | ||
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER | ||
``` | ||
### Configuration Variables | ||
**uprn** | ||
*(string) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: melton_gov_uk | ||
args: | ||
uprn: "100030544791" | ||
``` | ||
## 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.