-
Notifications
You must be signed in to change notification settings - Fork 100
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 #1056 from m26dvd/master
feat: Council Pack 20
- Loading branch information
Showing
10 changed files
with
255 additions
and
26 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
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
71 changes: 71 additions & 0 deletions
71
uk_bin_collection/uk_bin_collection/councils/HinckleyandBosworthBoroughCouncil.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,71 @@ | ||
import requests | ||
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: | ||
|
||
user_uprn = kwargs.get("uprn") | ||
check_uprn(user_uprn) | ||
bindata = {"bins": []} | ||
|
||
URI = f"https://www.hinckley-bosworth.gov.uk/set-location?id={user_uprn}&redirect=refuse&rememberloc=" | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the HTML | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
|
||
# Find all the bin collection date containers | ||
bin_schedule = [] | ||
collection_divs = soup.find_all( | ||
"div", class_=["first_date_bins", "last_date_bins"] | ||
) | ||
|
||
for div in collection_divs: | ||
# Extract the date | ||
date = div.find("h3", class_="collectiondate").text.strip().replace(":", "") | ||
|
||
# Extract bin types | ||
bins = [img["alt"] for img in div.find_all("img", class_="collection")] | ||
|
||
# Append to the schedule | ||
bin_schedule.append({"date": date, "bins": bins}) | ||
|
||
current_year = datetime.now().year | ||
current_month = datetime.now().month | ||
|
||
# Print the schedule | ||
for entry in bin_schedule: | ||
bin_types = entry["bins"] | ||
date = datetime.strptime(entry["date"], "%d %B") | ||
|
||
if (current_month > 9) and (date.month < 4): | ||
date = date.replace(year=(current_year + 1)) | ||
else: | ||
date = date.replace(year=current_year) | ||
|
||
for bin_type in bin_types: | ||
|
||
dict_data = { | ||
"type": bin_type, | ||
"collectionDate": date.strftime("%d/%m/%Y"), | ||
} | ||
bindata["bins"].append(dict_data) | ||
|
||
bindata["bins"].sort( | ||
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y") | ||
) | ||
|
||
return bindata |
70 changes: 70 additions & 0 deletions
70
uk_bin_collection/uk_bin_collection/councils/MonmouthshireCountyCouncil.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,70 @@ | ||
import requests | ||
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: | ||
|
||
user_uprn = kwargs.get("uprn") | ||
check_uprn(user_uprn) | ||
bindata = {"bins": []} | ||
|
||
URI = ( | ||
f"https://maps.monmouthshire.gov.uk/?action=SetAddress&UniqueId={user_uprn}" | ||
) | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the HTML | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
|
||
waste_collections_div = soup.find("div", {"aria-label": "Waste Collections"}) | ||
|
||
# Find all bin collection panels | ||
bin_panels = waste_collections_div.find_all("div", class_="atPanelContent") | ||
|
||
current_year = datetime.now().year | ||
current_month = datetime.now().month | ||
|
||
for panel in bin_panels: | ||
# Extract bin name (e.g., "Household rubbish bag") | ||
bin_name = panel.find("h4").text.strip().replace("\r", "").replace("\n", "") | ||
|
||
# Extract collection date (e.g., "Monday 9th December") | ||
date_tag = panel.find("p") | ||
if date_tag and "Your next collection date is" in date_tag.text: | ||
collection_date = date_tag.find("strong").text.strip() | ||
else: | ||
continue | ||
|
||
collection_date = datetime.strptime( | ||
remove_ordinal_indicator_from_date_string(collection_date), "%A %d %B" | ||
) | ||
|
||
if (current_month > 9) and (collection_date.month < 4): | ||
collection_date = collection_date.replace(year=(current_year + 1)) | ||
else: | ||
collection_date = collection_date.replace(year=current_year) | ||
|
||
dict_data = { | ||
"type": bin_name, | ||
"collectionDate": collection_date.strftime("%d/%m/%Y"), | ||
} | ||
bindata["bins"].append(dict_data) | ||
|
||
bindata["bins"].sort( | ||
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y") | ||
) | ||
|
||
return bindata |
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