-
Notifications
You must be signed in to change notification settings - Fork 95
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 #958 from m26dvd/master
feat: Council Pack 12
- Loading branch information
Showing
8 changed files
with
408 additions
and
24 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
56 changes: 56 additions & 0 deletions
56
uk_bin_collection/uk_bin_collection/councils/BlabyDistrictCouncil.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,56 @@ | ||
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://my.blaby.gov.uk/set-location.php?ref={user_uprn}&redirect=collections" | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the HTML | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
|
||
# Find each collection container based on the class "box-item" | ||
for container in soup.find_all(class_="box-item"): | ||
|
||
# Get the next collection dates from the <p> tag containing <strong> | ||
dates_tag = ( | ||
container.find("p", string=lambda text: "Next" in text) | ||
.find_next("p") | ||
.find("strong") | ||
) | ||
collection_dates = ( | ||
dates_tag.text.strip().split(", and then ") | ||
if dates_tag | ||
else "No dates found" | ||
) | ||
|
||
for collection_date in collection_dates: | ||
dict_data = { | ||
"type": container.find("h2").text.strip(), | ||
"collectionDate": collection_date, | ||
} | ||
bindata["bins"].append(dict_data) | ||
|
||
bindata["bins"].sort( | ||
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y") | ||
) | ||
|
||
return bindata |
55 changes: 55 additions & 0 deletions
55
uk_bin_collection/uk_bin_collection/councils/BromsgroveDistrictCouncil.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,55 @@ | ||
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://bincollections.bromsgrove.gov.uk/BinCollections/Details?uprn={user_uprn}" | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the HTML | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
|
||
# Find each collection container | ||
for container in soup.find_all(class_="collection-container"): | ||
# Get the bin type from the heading | ||
bin_type = container.find(class_="heading").text.strip() | ||
|
||
# Get the next collection date from the caption | ||
next_collection = ( | ||
container.find(class_="caption") | ||
.text.replace("Next collection ", "") | ||
.strip() | ||
) | ||
|
||
dict_data = { | ||
"type": bin_type, | ||
"collectionDate": datetime.strptime( | ||
next_collection, | ||
"%A, %d %B %Y", | ||
).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 |
55 changes: 55 additions & 0 deletions
55
uk_bin_collection/uk_bin_collection/councils/CarmarthenshireCountyCouncil.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,55 @@ | ||
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.carmarthenshire.gov.wales/umbraco/Surface/SurfaceRecycling/Index/?uprn={user_uprn}&lang=en-GB" | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the HTML | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
|
||
# Find each bin collection container | ||
for container in soup.find_all(class_="bin-day-container"): | ||
# Get the bin type based on the class (e.g., Blue, Black, Garden, Nappy) | ||
bin_type = container.get("class")[1] # Second class represents the bin type | ||
|
||
# Find the next collection date | ||
date_tag = container.find(class_="font11 text-center") | ||
if date_tag: | ||
collection_date = date_tag.text.strip() | ||
else: | ||
continue | ||
|
||
dict_data = { | ||
"type": bin_type, | ||
"collectionDate": datetime.strptime( | ||
collection_date, | ||
"%A %d/%m/%Y", | ||
).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 |
46 changes: 46 additions & 0 deletions
46
uk_bin_collection/uk_bin_collection/councils/EastAyrshireCouncil.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,46 @@ | ||
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.east-ayrshire.gov.uk/Housing/RubbishAndRecycling/Collection-days/ViewYourRecyclingCalendar.aspx?r={user_uprn}" | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the HTML | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
|
||
# Find each <time> element in the schedule | ||
for entry in soup.find_all("time"): | ||
|
||
dict_data = { | ||
"type": entry.find(class_="ScheduleItem").text.strip(), | ||
"collectionDate": datetime.strptime( | ||
entry["datetime"], | ||
"%Y-%m-%d", | ||
).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
Oops, something went wrong.