From e427b6a52e011402484b31eba43ced22c4497a61 Mon Sep 17 00:00:00 2001 From: Ryan Lowry Date: Sun, 20 Oct 2024 13:16:01 +0000 Subject: [PATCH] feat: Add Midlothgian Council --- uk_bin_collection/tests/input.json | 6 ++ .../councils/MidlothianCouncil.py | 68 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/MidlothianCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index e0441f4d8b..a4b1207794 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -719,6 +719,12 @@ "wiki_name": "Mid and East Antrim Borough Council", "wiki_note": "Pass the house name/number plus the name of the street with the postcode parameter, wrapped in double quotes. Check the address in the web site first. This version will only pick the first SHOW button returned by the search or if it is fully unique. The search is not very predictable (e.g. house number 4 returns 14,24,4,44 etc.)." }, + "MidlothianCouncil": { + "url": "https://www.midlothian.gov.uk/directory_record/92551426/glenesk_bonnyrigg_eh19_3je", + "wiki_command_url_override": "https://www.midlothian.gov.uk/directory_record/XXXXXX/XXXXXX", + "wiki_name": "Midlothian Council", + "wiki_note": "Follow the instructions [here](https://www.midlothian.gov.uk/info/1054/bins_and_recycling/343/bin_collection_days) until you get the page that shows the weekly collections for your address then copy the URL and replace the URL in the command." + }, "MidSussexDistrictCouncil": { "house_number": "OAKLANDS, OAKLANDS ROAD RH16 1SS", "postcode": "RH16 1SS", diff --git a/uk_bin_collection/uk_bin_collection/councils/MidlothianCouncil.py b/uk_bin_collection/uk_bin_collection/councils/MidlothianCouncil.py new file mode 100644 index 0000000000..4009798a54 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/MidlothianCouncil.py @@ -0,0 +1,68 @@ +from bs4 import BeautifulSoup + +from uk_bin_collection.uk_bin_collection.common import * +from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass + + +# import the wonderful Beautiful Soup and the URL grabber +class CouncilClass(AbstractGetBinDataClass): + """ + Concrete classes have to implement all abstract operations of the + base class. They can also override some operations with a default + implementation. + """ + + def parse_data(self, page: str, **kwargs) -> dict: + # Parse the HTML content using BeautifulSoup + soup = BeautifulSoup(page.text, features="html.parser") + + # Initialize a dictionary to store the parsed bin data + data = {"bins": []} + + # Define a mapping of bin collection labels to their corresponding types + bin_types = { + "Next recycling collection": "Recycling", + "Next grey bin collection": "Grey Bin", + "Next brown bin collection": "Brown Bin", + "Next food bin collection": "Food Bin", + } + + # Locate the