Skip to content

Commit

Permalink
Merge pull request #462 from dp247/445-dorset-council
Browse files Browse the repository at this point in the history
  • Loading branch information
robbrad authored Dec 5, 2023
2 parents 8493916 + 8b091f4 commit 45b8690
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Feature: Test each council output matches expected results
| CroydonCouncil | None | None |
| DerbyshireDalesDistrictCouncil | http://selenium:4444 | local |
| DoncasterCouncil | None | None |
| DorsetCouncil | None | None |
| DurhamCouncil | None | None |
| EastCambridgeshireCouncil | None | None |
| EastDevonDC | None | None |
Expand Down
6 changes: 6 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
"url": "https://www.doncaster.gov.uk/Compass/Entity/Launch/D3/",
"wiki_name": "Doncaster Council"
},
"DorsetCouncil": {
"url": "https://gi.dorsetcouncil.gov.uk/mapping/mylocal/viewresults/100040711049",
"wiki_command_url_override": "https://gi.dorsetcouncil.gov.uk/mapping/mylocal/viewresults/XXXXXXXX",
"wiki_name": "Dorset Council",
"wiki_note": "Replace XXXXXXXX with UPRN."
},
"DurhamCouncil": {
"skip_get_url": true,
"uprn": "200003218818",
Expand Down
51 changes: 51 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/DorsetCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from bs4 import BeautifulSoup, element
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:
data = {"bins": []}
collections = []

# Parse the page and find all the result boxes
soup = BeautifulSoup(page.text, features="html.parser")
soup.prettify()
results = soup.find_all("li", {"class": "resultListItem"})

# If the result box has a wanted string in, we can use it. Check the contents of each box and find the
# desired text and dates
for r in results:
if 'Your next' in r.text:
if type(r.contents[10]) is element.NavigableString:
bin_text = r.contents[10].text.split(' ')[2].title() + ' bin'
bin_date = datetime.strptime(remove_ordinal_indicator_from_date_string(r.contents[11].text.strip()),
"%A %d %B %Y")
else:
bin_text = r.contents[11].text.split(' ')[2].title() + ' bin'
bin_date = datetime.strptime(remove_ordinal_indicator_from_date_string(r.contents[12].text.strip()),
"%A %d %B %Y")

if bin_date.date() >= datetime.now().date():
collections.append((bin_text, bin_date))

# Sort the text and date elements by date
ordered_data = sorted(collections, key=lambda x: x[1])

# Put the elements into the dictionary
for item in ordered_data:
dict_data = {
"type": item[0],
"collectionDate": item[1].strftime(date_format),
}
data["bins"].append(dict_data)

return data

0 comments on commit 45b8690

Please sign in to comment.