-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #441 from dp247/433-lewes-and-eastbourne-environme…
…ntfirst-council-request feat: Add support for EnvironmentFirst collections
- Loading branch information
Showing
4 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
uk_bin_collection/uk_bin_collection/councils/EnvironmentFirst.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |