Skip to content

Commit

Permalink
Add Chelmsford City Council source
Browse files Browse the repository at this point in the history
  • Loading branch information
jonware committed Sep 30, 2024
1 parent f05de7e commit 8736460
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Carmarthenshire County Council](/doc/source/carmarthenshire_gov_wales.md) / carmarthenshire.gov.wales
- [Central Bedfordshire Council](/doc/source/centralbedfordshire_gov_uk.md) / centralbedfordshire.gov.uk
- [Charnwood](/doc/source/charnwood_gov_uk.md) / charnwood.gov.uk
- [Chelmsford City Council](/doc/source/chelmsford_gov_uk.md) / chelmsford.gov.uk
- [Cherwell District Council](/doc/source/cherwell_gov_uk.md) / cherwell.gov.uk
- [Cheshire East Council](/doc/source/cheshire_east_gov_uk.md) / cheshireeast.gov.uk
- [Cheshire West and Chester Council](/doc/source/cheshire_west_and_chester_gov_uk.md) / cheshirewestandchester.gov.uk
Expand Down
6 changes: 6 additions & 0 deletions custom_components/waste_collection_schedule/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -10506,6 +10506,12 @@
"default_params": {},
"id": "charnwood_gov_uk"
},
{
"title": "Chelmsford City Council",
"module": "chelmsford_gov_uk",
"default_params": {},
"id": "chelmsford_gov_uk"
},
{
"title": "Cherwell District Council",
"module": "cherwell_gov_uk",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -15700,6 +15700,26 @@
"calendar_title": "Kalender Titel"
},
"data_description": {}
},
"args_chelmsford_gov_uk": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nYou can find your collection round by visiting https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/chelmsford_gov_uk.md",
"data": {
"calendar_title": "Kalender Titel",
"collection_round": "Collection Round"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
}
},
"reconfigure_chelmsford_gov_uk": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nYou can find your collection round by visiting https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/chelmsford_gov_uk.md",
"data": {
"calendar_title": "Kalender Titel",
"collection_round": "Collection Round"
},
"data_description": {}
}
},
"error": {
Expand Down
23 changes: 23 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15700,6 +15700,29 @@
"calendar_title": "Calendar Title"
},
"data_description": {}
},
"args_chelmsford_gov_uk": {
"title": "Configure Source",
"description": "Configure your service provider. \n\nYou can find your collection round by visiting https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/chelmsford_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"collection_round": "Collection Round"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used.",
"collection_round": "Collection round identifier (e.g. Tuesday A). You can find yours by going to https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details."
}
},
"reconfigure_chelmsford_gov_uk": {
"title": "Reconfigure Source",
"description": "Configure your service provider. \n\nYou can find your collection round by visiting https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/chelmsford_gov_uk.md.",
"data": {
"calendar_title": "Calendar Title",
"collection_round": "Collection Round"
},
"data_description": {
"collection_round": "Collection round identifier (e.g. Tuesday A). You can find yours by going to https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details."
}
}
},
"error": {
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -15675,6 +15675,26 @@
"calendar_title": "Nome Calendario"
},
"data_description": {}
},
"args_chelmsford_gov_uk": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nYou can find your collection round by visiting https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/chelmsford_gov_uk.md.",
"data": {
"calendar_title": "Nome Calendario",
"collection_round": "Collection Round"
},
"data_description": {
"calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi."
}
},
"reconfigure_chelmsford_gov_uk": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nYou can find your collection round by visiting https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.\n\nPer maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/chelmsford_gov_uk.md.",
"data": {
"calendar_title": "Nome Calendario",
"collection_round": "Collection Round"
},
"data_description": {}
}
},
"error": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import requests
from bs4 import BeautifulSoup
from datetime import datetime
from waste_collection_schedule import Collection


TITLE = "Chelmsford City Council"
DESCRIPTION = "Source for Chelmsford City Council, UK"
URL = "https://www.chelmsford.gov.uk/"
COUNTRY = "uk"
TEST_CASES = {
"Test_001": {"collection_round": "Tuesday A"},
"Test_002": {"collection_round": "Thursday B"},
}

ICON_MAP = {
"food waste": "mdi:food-apple",
"black bin": "mdi:trash-can",
"brown bin": "mdi:leaf",
"green box": "mdi:bottle-soda",
"paper sack": "mdi:newspaper",
"card sack": "mdi:package-variant",
"plastic and cartons bag": "mdi:recycle"
}

#### Arguments affecting the configuration GUI ####

HOW_TO_GET_ARGUMENTS_DESCRIPTION = { # Optional dictionary to describe how to get the arguments, will be shown in the GUI configuration form above the input fields, does not need to be translated in all languages
"en": "You can find your collection round by visiting https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.",
}

PARAM_DESCRIPTIONS = { # Optional dict to describe the arguments, will be shown in the GUI configuration below the respective input field
"en": {
"collection_round": "Collection round identifier (e.g. Tuesday A). You can find yours by going to https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.",
},
}

class Source:
def __init__(self, collection_round):
self._collection_round = collection_round

def fetch(self) -> list[Collection]:
url = f"https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day/{self._collection_round.lower().replace(' ', '-')}-collection-calendar/"

r = requests.get(url)
r.raise_for_status()

soup = BeautifulSoup(r.content, 'html.parser')

divs = soup.find_all('div', class_='textcontent')

entries = []

for div in divs:
heading_items = div.find_all(['h2'])
list_items = div.find_all(['ul', 'ol'])

for list in list_items:
items = list.find_all('li')
for item in items:
it = item.get_text(strip=True)
date_str, items = it.split(':')
day, date, month = date_str.split()

year = None
for h in heading_items:
heading = h.get_text(strip=True)
if month in heading:
year=heading.split()[1]
break

date = datetime.strptime(f"{date} {month} {year}", "%d %B %Y").date()
for i in items.split(','):
waste_type=i.strip()
entries.append(
Collection(
date=date,
t=waste_type.title(),
icon=ICON_MAP.get(waste_type),
)
)
return entries
34 changes: 34 additions & 0 deletions doc/source/chelmsford_gov_uk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Chelmsford City Council

Support for schedules provided by [Chelmsford City Council](https://www.chelmsford.gov.uk), serving Chelmsford, Essex, UK.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: chelmsford_gov_uk
args:
collection_round: "Collection Round"

```
### Configuration Variables
**collection_round**
*(String) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: chelmsford_gov_uk
args:
collection_round: "Tuesday B"

```
## How to get the source argument
You can find your collection round by visiting https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day and entering in your address details.
Loading

0 comments on commit 8736460

Please sign in to comment.