-
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 #809 from domdomegg/IslingtonCouncil
feat: Add IslingtonCouncil
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 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
37 changes: 37 additions & 0 deletions
37
uk_bin_collection/uk_bin_collection/councils/IslingtonCouncil.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,37 @@ | ||
from bs4 import BeautifulSoup | ||
from dateutil.parser import parse | ||
|
||
from uk_bin_collection.uk_bin_collection.common import * | ||
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass | ||
|
||
|
||
class CouncilClass(AbstractGetBinDataClass): | ||
def parse_data(self, page: str, **kwargs) -> dict: | ||
uprn = kwargs.get("uprn") | ||
check_uprn(uprn) | ||
|
||
api_url = f"https://www.islington.gov.uk/your-area?Postcode=unused&Uprn={uprn}" | ||
response = requests.get(api_url) | ||
|
||
soup = BeautifulSoup(response.text, features="html.parser") | ||
|
||
data = {"bins": []} | ||
|
||
waste_table = ( | ||
soup.find(string="Waste and recycling collections") | ||
.find_next("div", class_="m-toggle-content") | ||
.find("table") | ||
) | ||
|
||
if waste_table: | ||
rows = waste_table.find_all("tr") | ||
for row in rows: | ||
waste_type = row.find("th").text.strip() | ||
next_collection = parse(row.find("td").text.strip()).date() | ||
|
||
data['bins'].append({ | ||
"type": waste_type, | ||
"collectionDate": next_collection.strftime(date_format), | ||
}) | ||
|
||
return data |