-
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.
- Loading branch information
1 parent
0ed259f
commit e5aa84a
Showing
2 changed files
with
71 additions
and
15 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
51 changes: 51 additions & 0 deletions
51
uk_bin_collection/uk_bin_collection/councils/RotherhamCouncil.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,51 @@ | ||
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) | ||
|
||
response = requests.post( | ||
"https://www.rotherham.gov.uk/bin-collections?address={}&submit=Submit".format(user_uprn) | ||
) | ||
# Make a BS4 object | ||
soup = BeautifulSoup(response.text, features="html.parser") | ||
soup.prettify() | ||
|
||
data = {"bins": []} | ||
|
||
table = soup.select('table')[0] | ||
|
||
if table: | ||
rows = table.select('tr') | ||
|
||
for index, row in enumerate(rows): | ||
bin_info_cell = row.select('td') | ||
if bin_info_cell: | ||
bin_type = bin_info_cell[0].get_text(separator=' ', strip=True) | ||
bin_collection = bin_info_cell[1] | ||
|
||
if bin_collection: | ||
dict_data = { | ||
"type": bin_type.title(), | ||
"collectionDate": datetime.strptime( | ||
bin_collection.get_text(strip=True), "%A, %d %B %Y" | ||
).strftime(date_format), | ||
} | ||
|
||
data["bins"].append(dict_data) | ||
else: | ||
print("Something went wrong. Please open a GitHub issue.") | ||
|
||
return data |