Add source islington_gov_uk (#2648)

* Add source islington_gov_uk

Fixes #2646

* Add support for business address bin types

* reformatting + modified one test case from string to integer

---------

Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
Adam Jones
2024-09-10 18:43:57 +02:00
committed by GitHub
parent e85901269d
commit ec22c9252f
5 changed files with 102 additions and 1 deletions

View File

@@ -1669,6 +1669,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Horsham District Council](/doc/source/horsham_gov_uk.md) / horsham.gov.uk
- [Hull City Council](/doc/source/hull_gov_uk.md) / hull.gov.uk
- [Huntingdonshire District Council](/doc/source/huntingdonshire_gov_uk.md) / huntingdonshire.gov.uk
- [Islington Council](/doc/source/islington_gov_uk.md) / islington.gov.uk
- [iTouchVision](/doc/source/iweb_itouchvision_com.md) / iweb.itouchvision.com
- [Itouchvision Source using the encrypted API](/doc/source/iapp_itouchvision_com.md) / itouchvision.com
- [Joint Waste Solutions](/doc/source/jointwastesolutions_org.md) / jointwastesolutions.org

View File

@@ -9086,6 +9086,11 @@
"module": "huntingdonshire_gov_uk",
"default_params": {}
},
{
"title": "Islington Council",
"module": "islington_gov_uk",
"default_params": {}
},
{
"title": "iTouchVision",
"module": "iweb_itouchvision_com",

View File

@@ -0,0 +1,60 @@
import requests
from bs4 import BeautifulSoup
from dateutil.parser import parse
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Islington Council"
DESCRIPTION = "Source for Islington Council, UK."
URL = "https://www.islington.gov.uk"
TEST_CASES = {
"Test_001": {"uprn": "5300094897"},
"Test_002": {"uprn": 10001295652},
}
ICON_MAP = {
"Green recycling box": "mdi:recycle",
"Dry recycling bin": "mdi:recycle",
"Communal dry recycling bin": "mdi:recycle",
"Small kitchen waste box": "mdi:food",
"Large brown kitchen waste box": "mdi:food",
"Reuseable garden waste sack": "mdi:leaf",
"Household refuse sack": "mdi:trash-can",
"Refuse skip": "mdi:trash-can",
}
class Source:
def __init__(self, uprn):
self._uprn = str(uprn)
self._session = requests.Session()
def fetch(self):
url = (
f"https://www.islington.gov.uk/your-area?Postcode=unused&Uprn={self._uprn}"
)
response = self._session.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
entries = []
waste_table = (
soup.find(string="Waste and recycling collections")
.find_next("div", class_="m-toggle-content")
.find("table")
)
if waste_table:
rows = waste_table.find_all("tr")
for row in rows:
waste_type = row.find("th").text.strip()
collection_day = row.find("td").text.strip()
entries.append(
Collection(
date=parse(collection_day).date(),
t=waste_type,
icon=ICON_MAP.get(waste_type),
)
)
return entries

View File

@@ -0,0 +1,35 @@
# Islington Council
Support for schedules provided by [Islington Council](https://www.islington.gov.uk/), serving Islington, London, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: islington_gov_uk
args:
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER
```
### Configuration Variables
**uprn**<br>
*(string) (required)*
## Example using UPRN
```yaml
waste_collection_schedule:
sources:
- name: islington_gov_uk
args:
uprn: "10001295652"
```
#### How to find your `UPRN`
Select your address on <https://www.islington.gov.uk/your-area>. You get redirected to your collection overview. The URL contains your UPRN (`https://www.islington.gov.uk/your-area?Postcode=unused&Uprn={UPRN}`)
Alternatively, you can discover what your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details.

File diff suppressed because one or more lines are too long