Skip to content

Commit

Permalink
Merge pull request #342 from thinkl33t/thinkl33t/manchester-city-council
Browse files Browse the repository at this point in the history
Add source for manchester city council.
  • Loading branch information
mampfes authored Aug 27, 2022
2 parents 6ded8ee + e10dbc4 commit 42eb296
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 changes: 38 additions & 0 deletions doc/source/manchester_uk.md
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,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)
Expand Down

0 comments on commit 42eb296

Please sign in to comment.