Skip to content

Commit

Permalink
Merge pull request #809 from domdomegg/IslingtonCouncil
Browse files Browse the repository at this point in the history
feat: Add IslingtonCouncil
  • Loading branch information
robbrad authored Sep 9, 2024
2 parents 1fd43f7 + 98f8ce0 commit c8833c9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,13 @@
"wiki_name": "Huntingdon District Council",
"wiki_note": "Replace XXXXXXXX with UPRN."
},
"IslingtonCouncil": {
"uprn": "5300094897",
"url": "https://www.islington.gov.uk/your-area?Postcode=unused&Uprn=5300094897",
"wiki_command_url_override": "https://www.islington.gov.uk/your-area?Postcode=unused&Uprn=XXXXXXXX",
"wiki_name": "Islington Council",
"wiki_note": "Replace XXXXXXXX with UPRN."
},
"KingstonUponThamesCouncil": {
"url": "https://waste-services.kingston.gov.uk/waste/2701097",
"wiki_command_url_override": "https://waste-services.kingston.gov.uk/waste/XXXXXXX",
Expand Down
37 changes: 37 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/IslingtonCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from bs4 import BeautifulSoup
from dateutil.parser import parse

from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass


class CouncilClass(AbstractGetBinDataClass):
def parse_data(self, page: str, **kwargs) -> dict:
uprn = kwargs.get("uprn")
check_uprn(uprn)

api_url = f"https://www.islington.gov.uk/your-area?Postcode=unused&Uprn={uprn}"
response = requests.get(api_url)

soup = BeautifulSoup(response.text, features="html.parser")

data = {"bins": []}

waste_table = (
soup.find(string="Waste and recycling collections")
.find_next("div", class_="m-toggle-content")
.find("table")
)

if waste_table:
rows = waste_table.find_all("tr")
for row in rows:
waste_type = row.find("th").text.strip()
next_collection = parse(row.find("td").text.strip()).date()

data['bins'].append({
"type": waste_type,
"collectionDate": next_collection.strftime(date_format),
})

return data

0 comments on commit c8833c9

Please sign in to comment.