Skip to content

Commit

Permalink
feat: #264 Adding Oldham
Browse files Browse the repository at this point in the history
  • Loading branch information
robbrad committed Dec 16, 2023
1 parent 9be8072 commit d127a9f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Feature: Test each council output matches expected results
| NorthTynesideCouncil | None | None |
| NorthumberlandCouncil | http://selenium:4444 | local |
| NorthWestLeicestershire | http://selenium:4444 | local |
| OldhamCouncil | None | None |
| PortsmouthCityCouncil | http://selenium:4444 | local |
| PrestonCityCouncil | http://selenium:4444 | local |
| ReadingBoroughCouncil | None | None |
Expand Down
5 changes: 5 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@
"url": "https://www.northumberland.gov.uk/Waste/Bins/Bin-Calendars.aspx",
"web_driver": "http://selenium:4444",
"wiki_name": "Northumberland Council"
},
"OldhamCouncil": {
"url": "https://portal.oldham.gov.uk/bincollectiondates/details?uprn=422000033556",
"wiki_name": "Oldham Council",
"wiki_note": "Replace UPRN in URL with your own UPRN."
},
"PortsmouthCityCouncil": {
"skip_get_url": true,
Expand Down
51 changes: 51 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/OldhamCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import \
AbstractGetBinDataClass

from bs4 import BeautifulSoup


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:

data = {"bins": []}
soup = BeautifulSoup(page.text, 'html.parser')

# Find all tables with the class "data-table confirmation"
tables = soup.find_all('table', class_='data-table confirmation')
for table in tables:
rows = table.find_all('tr')
bin_type = None
bin_collection = None

# Search for the bin color in the table headers
th_element = table.find('th')
if th_element:
bin_type = th_element.text.strip()

for row in rows:
header = row.find('b')
if header:
header_text = header.text.strip()
value_cell = row.find('td', class_='coltwo')
if value_cell:
value_text = value_cell.text.strip()

if header_text == 'Collection Date':
bin_collection = value_text

if bin_type and bin_collection:
dict_data = {
"type": bin_type,
"collectionDate": datetime.strptime(bin_collection, "%d/%m/%Y").strftime(date_format)
}

data["bins"].append(dict_data)

return data

0 comments on commit d127a9f

Please sign in to comment.