This project aims to provide a neat and standard way of providing bin collection data in JSON format from UK councils that have no API to do so.
Why do this? You might want to use this in a Home Automation - for example say you had an LED bar that lit up on the day of bin collection to the colour of the bin you want to take out, then this repo provides the data for that.
PLEASE respect a councils infrastructure / usage policy and only collect data for your own personal use on a sutable frequency to your collection schedule.
Most scripts make use of Beautiful Soup 4 to scrape data, although others use different approaches, such as emulating web browser behaviour, or reading data from CSV files.
PS G:\Projects\Python\UKBinCollectionData\uk_bin_collection\collect_data.py
usage: collect_data.py [-h] [-p POSTCODE] [-n NUMBER] [-u UPRN] module URL
positional arguments:
module Name of council module to use (required)
URL URL to parse (required)
options:
-h, --help show this help message (optional)
-p POSTCODE, --postcode POSTCODE Postcode to parse - should include (optional)
a space and be wrapped in double
quotes
-n NUMBER, --number NUMBER House number to parse (optional)
-u UPRN, --uprn UPRN UPRN to parse (optional)
The basic command to execute a script is:
python collect_data.py <council_name> "<collection_url>"
where council_name
is the name of the council's .py script (without the .py) and collection_url
is the URL to scrape.
The help documentation refers to these as "module" and "URL", respectively. Supported council scripts can be found in the uk_bin_collection/uk_bin_collection/councils
folder.
Some scripts require additional parameters, for example, when a UPRN is not passed in a URL, or when the script is not scraping a web page. For example, the Leeds City Council script needs two additional parameters - a postcode, and a house number. This is done like so:
python collect_data.py LeedsCityCouncil https://www.leeds.gov.uk/residents/bins-and-recycling/check-your-bin-day -p "LS1 2JG" -n 41
- A postcode can be passed with
-p "postcode"
or--postcode "postcode"
. The postcode must always include a space in the middle and be wrapped in double quotes (due to how command line arguments are handled). - A house number can be passed with
-n number
or--number number
. - A UPRN reference can be passed with
-u uprn
or--uprn uprn
.
To check the parameters needed for your council's script, please check the project wiki for more information.
Some scripts rely on external packages to function. A list of required scripts for both development and execution can be found in the project's PROJECT_TOML
Install can be done via
poetry install
from within the root of the repo.
Some councils make use of the UPRN (Unique property reference number) to identify your property. You can find yours here or here.
To make a request for your council, first check the Issues page to make sure it has not already been requested. If not, please fill in a new Council Request form, including as much information as possible, including:
- Name of the council
- URL to bin collections
- An example postcode and/or UPRN (whichever is relevant)
- Any further information
Please be aware that this project is run by volunteer contributors and completion depends on numerous factors - even with a request, we cannot guarantee if/when your council will get a script.
Please post in the HomeAssistant thread or raise a new (non council request) issue.
Contributions are always welcome! See CONTRIBUTING.md
to get started. Please adhere to the project's code of conduct.
- If you're new to coding/Python/BeautifulSoup, feel free to check here for issues that are good for newcomers!
- If you would like to try writing your own scraper, feel free to fork this project and use existing scrapers as a base for your approach (or
councilclasstemplate.py
).