Skip to content

Commit

Permalink
Merge pull request #441 from dp247/433-lewes-and-eastbourne-environme…
Browse files Browse the repository at this point in the history
…ntfirst-council-request

feat: Add support for EnvironmentFirst collections
  • Loading branch information
OliverCullimore authored Dec 1, 2023
2 parents 034920a + c8f742f commit 8793814
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Feature: Test each council output matches expected results
| EastLindseyDistrictCouncil | http://selenium:4444 | local |
| EastRidingCouncil | None | None |
| EastSuffolkCouncil | http://selenium:4444 | local |
| EnvironmentFirst | None | None |
| ErewashBoroughCouncil | None | None |
| FenlandDistrictCouncil | None | None |
| GatesheadCouncil | http://selenium:4444 | local |
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 @@ -212,6 +212,12 @@
"url": "https://www.eastleigh.gov.uk/waste-bins-and-recycling/collection-dates/your-waste-bin-and-recycling-collections?uprn=",
"wiki_name": "Eastleigh Borough Council"
},
"EnvironmentFirst": {
"url": "https://environmentfirst.co.uk/house.php?uprn=100060055444",
"wiki_command_url_override": "https://environmentfirst.co.uk/house.php?uprn=XXXXXXXXXX",
"wiki_name": "Environment First",
"wiki_note": "For properties with collections managed by Environment First, such as Lewes and Eastbourne.\nReplace the XXXXXXXXXXX with the UPRN of your property - you can use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find this."
},
"ErewashBoroughCouncil": {
"skip_get_url": true,
"uprn": "10003582028",
Expand Down
6 changes: 3 additions & 3 deletions uk_bin_collection/uk_bin_collection/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,18 @@ def get_weekday_dates_in_period(start: datetime, day_of_week: int, amount=8) ->
)


def get_dates_every_x_days(start: datetime, x: int, amount: int = 8) -> list:
def get_dates_every_x_days(start: datetime, step: int, amount: int = 8) -> list:
"""
Returns a list of dates for `X` days from start date. For example, calling `get_stepped_dates_in_period(s, 21, 4)` would
return `4` dates every `21` days from the start date `s`
:param start: Date to start from
:param x: X amount of days
:param step: X amount of days
:param amount: Number of dates to find
:return: List of dates every X days from start date
:rtype: list
"""
return (
pd.date_range(start=start, freq=f"{x}D", periods=amount)
pd.date_range(start=start, freq=f"{step}D", periods=amount)
.strftime(date_format)
.tolist()
)
Expand Down
40 changes: 40 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/EnvironmentFirst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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:
# Make a BS4 object
soup = BeautifulSoup(page.text, features="html.parser")
soup.prettify()

# Get the paragraph lines from the page
data = {"bins": []}
page_text = soup.find("div", {"class": "collect"}).find_all("p")

# Parse the correct lines (find them, remove the ordinal indicator and make them the correct format date) and
# then add them to the dictionary
rubbish_day = datetime.strptime(remove_ordinal_indicator_from_date_string(page_text[2].find_next("strong").text), "%d %B %Y").strftime(date_format)
dict_data = {
"type": "Rubbish",
"collectionDate": rubbish_day,
}
data["bins"].append(dict_data)
recycling_day = datetime.strptime(remove_ordinal_indicator_from_date_string(page_text[4].find_next("strong").text), "%d %B %Y").strftime(date_format)
dict_data = {
"type": "Recycling",
"collectionDate": recycling_day,
}
data["bins"].append(dict_data)


return data

0 comments on commit 8793814

Please sign in to comment.