mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
Add source for manchester city council.
This commit is contained in:
@@ -167,6 +167,7 @@ Currently the following service providers are supported:
|
||||
- [Lewes District Council - lewes-eastbourne.gov.uk](./doc/source/environmentfirst_co_uk.md)
|
||||
- [Harborough District Council - www.harborough.gov.uk](./doc/source/fccenvironment_co_uk.md)
|
||||
- [Huntingdonshire District Council - huntingdonshire.gov.uk](./doc/source/huntingdonshire_gov_uk.md)
|
||||
- [Manchester City Council - manchester.gov.uk](./doc/source/manchester_uk.md)
|
||||
- [North Somerset Council - n-somerset.gov.uk](./doc/source/nsomerset_gov_uk.md)
|
||||
- [Nottingham City Council - nottinghamcity.gov.uk](./doc/source/nottingham_city_gov_uk.md)
|
||||
- [Peterborough City Council - peterborough.gov.uk](./doc/source/peterborough_gov_uk.md)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from urllib.parse import urlsplit, parse_qs
|
||||
import logging
|
||||
|
||||
TITLE = "manchester.gov.uk"
|
||||
DESCRIPTION = "Source for bin collection services for Manchester City Council, UK."
|
||||
URL = "https://www.manchester.gov.uk/bincollections/"
|
||||
TEST_CASES = {
|
||||
"domestic": {'uprn': '000077065560'},
|
||||
}
|
||||
|
||||
ICONS = {
|
||||
"Black / Grey Bin": "mdi:trash-can",
|
||||
"Blue Bin": "mdi:recycle",
|
||||
"Brown Bin": "mdi:glass-fragile",
|
||||
"Green Bin": "mdi:leaf",
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(
|
||||
self, uprn: int = None
|
||||
):
|
||||
self._uprn = uprn
|
||||
if not self._uprn:
|
||||
_LOGGER.error(
|
||||
"uprn must be provided in config"
|
||||
)
|
||||
self._session = requests.Session()
|
||||
|
||||
def fetch(self):
|
||||
entries = []
|
||||
|
||||
r = requests.post(
|
||||
URL,
|
||||
data={
|
||||
"mcc_bin_dates_uprn": self._uprn,
|
||||
"mcc_bin_dates_submit": "Go"
|
||||
},
|
||||
)
|
||||
|
||||
soup = BeautifulSoup(r.text, features="html.parser")
|
||||
results = soup.find_all("div", {"class": "collection"})
|
||||
|
||||
for result in results:
|
||||
date = result.find("p", {"class": "caption"})
|
||||
dates = []
|
||||
dates.append(str(date.text).replace("Next collection ", "", 1))
|
||||
for date in result.find_all('li'):
|
||||
dates.append(date.text)
|
||||
img_tag = result.find("img")
|
||||
collection_type = img_tag["alt"]
|
||||
for current_date in dates:
|
||||
try:
|
||||
date = datetime.strptime(current_date, "%A %d %b %Y").date()
|
||||
entries.append(
|
||||
Collection(
|
||||
date=date,
|
||||
t=collection_type,
|
||||
icon=ICONS[collection_type],
|
||||
)
|
||||
)
|
||||
except ValueError:
|
||||
_LOGGER.error(f"Skipped {current_date} as it does not match time format")
|
||||
|
||||
return entries
|
||||
38
doc/source/manchester_uk.md
Normal file
38
doc/source/manchester_uk.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Manchester City Council
|
||||
|
||||
Support for schedules provided by [Manchester City
|
||||
Council](https://www.manchester.gov.uk/bincollections/), serving the
|
||||
city of Manchester, UK.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: manchester_uk
|
||||
args:
|
||||
uprn: UPRN_CODE
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**uprn**<br>
|
||||
*(string) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: manchester_uk
|
||||
args:
|
||||
uprn: "100031540175"
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
The UPRN code can be found in the page by entering your postcode on the
|
||||
[Manchester City Council Bin Collections page
|
||||
](https://www.manchester.gov.uk/bincollections/). When on the address list,
|
||||
View the source code for the page, and look for your address, the uprn will be
|
||||
shown as the value.
|
||||
1
info.md
1
info.md
@@ -153,6 +153,7 @@ Currently the following service providers are supported:
|
||||
- [Lewes District Council - lewes-eastbourne.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/environmentfirst_co_uk.md)
|
||||
- [Harborough District Council - www.harborough.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/fccenvironment_co_uk.md)
|
||||
- [Huntingdonshire District Council - huntingdonshire.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/huntingdonshire_gov_uk.md)
|
||||
- [Manchester City Council - manchester.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/manchester_uk.md)
|
||||
- [North Somerset Council - n-somerset.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/nsomerset_gov_uk.md)
|
||||
- [Nottingham City Council - nottinghamcity.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/nottingham_city_gov_uk.md)
|
||||
- [Peterborough City Council - peterborough.gov.uk](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/peterborough_gov_uk.md)
|
||||
|
||||
Reference in New Issue
Block a user