-
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 #986 from m26dvd/master
fix: Council Pack 14
- Loading branch information
Showing
8 changed files
with
904 additions
and
143 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
53 changes: 53 additions & 0 deletions
53
uk_bin_collection/uk_bin_collection/councils/AntrimAndNewtonabbeyCouncil.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,53 @@ | ||
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: | ||
|
||
bindata = {"bins": []} | ||
|
||
soup = BeautifulSoup(page.content, "html.parser") | ||
soup.prettify | ||
|
||
collection_divs = soup.select("div.feature-box.bins") | ||
if not collection_divs: | ||
raise Exception("No collections found") | ||
|
||
for collection_div in collection_divs: | ||
date_p = collection_div.select_one("p.date") | ||
if not date_p: | ||
continue | ||
|
||
# Thu 22 Aug, 2024 | ||
date_ = datetime.strptime(date_p.text.strip(), "%a %d %b, %Y").strftime( | ||
"%d/%m/%Y" | ||
) | ||
bins = collection_div.select("li") | ||
if not bins: | ||
continue | ||
for bin in bins: | ||
if not bin.text.strip(): | ||
continue | ||
bin_type = bin.text.strip() | ||
|
||
dict_data = { | ||
"type": bin_type, | ||
"collectionDate": date_, | ||
} | ||
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
71 changes: 71 additions & 0 deletions
71
uk_bin_collection/uk_bin_collection/councils/BroxbourneCouncil.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 @@ | ||
from datetime import datetime | ||
|
||
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 | ||
|
||
|
||
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") | ||
user_postcode = kwargs.get("postcode") | ||
check_uprn(user_uprn) | ||
check_postcode(user_postcode) | ||
bindata = {"bins": []} | ||
|
||
API_URL = "https://www.broxbourne.gov.uk/xfp/form/205" | ||
|
||
post_data = { | ||
"page": "490", | ||
"locale": "en_GB", | ||
"qacf7e570cf99fae4cb3a2e14d5a75fd0d6561058_0_0": user_postcode, | ||
"qacf7e570cf99fae4cb3a2e14d5a75fd0d6561058_1_0": user_uprn, | ||
"next": "Next", | ||
} | ||
|
||
r = requests.post(API_URL, data=post_data) | ||
r.raise_for_status() | ||
|
||
soup = BeautifulSoup(r.content, features="html.parser") | ||
soup.prettify() | ||
|
||
form__instructions = soup.find(attrs={"class": "form__instructions"}) | ||
table = form__instructions.find("table") | ||
|
||
rows = table.find_all("tr") | ||
|
||
current_year = datetime.now().year | ||
|
||
# Process each row into a list of dictionaries | ||
for row in rows[1:]: # Skip the header row | ||
columns = row.find_all("td") | ||
collection_date = ( | ||
columns[0].get_text(separator=" ").replace("\xa0", " ").strip() | ||
) | ||
service = columns[1].get_text(separator=" ").replace("\xa0", " ").strip() | ||
|
||
collection_date = datetime.strptime(collection_date, "%a %d %b") | ||
|
||
if collection_date.month == 1: | ||
collection_date = collection_date.replace(year=current_year + 1) | ||
else: | ||
collection_date = collection_date.replace(year=current_year) | ||
|
||
dict_data = { | ||
"type": service, | ||
"collectionDate": (collection_date).strftime(date_format), | ||
} | ||
bindata["bins"].append(dict_data) | ||
|
||
bindata["bins"].sort( | ||
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y") | ||
) | ||
return bindata |
Oops, something went wrong.