-
Notifications
You must be signed in to change notification settings - Fork 111
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 #597 from stuartmacd/feat-add-stAlbans
feat: Add Scraper for St Albans City and District Council
- Loading branch information
Showing
3 changed files
with
59 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
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
48 changes: 48 additions & 0 deletions
48
uk_bin_collection/uk_bin_collection/councils/StAlbansCityAndDistrictCouncil.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,48 @@ | ||
from uk_bin_collection.uk_bin_collection.common import * | ||
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass | ||
from dateutil import parser | ||
|
||
|
||
class CouncilClass(AbstractGetBinDataClass): | ||
def parse_data(self, page: str, **kwargs) -> dict: | ||
user_uprn = kwargs.get("uprn") | ||
check_uprn(user_uprn) | ||
|
||
data = { | ||
"bins": [] | ||
} | ||
|
||
headers = { | ||
"Content-Type": "application/json; charset=UTF-8", | ||
} | ||
|
||
req_data = { | ||
"uprn": user_uprn, | ||
"noticeBoard": "default" | ||
} | ||
|
||
url = "https://gis.stalbans.gov.uk/NoticeBoard9/VeoliaProxy.NoticeBoard.asmx/GetServicesByUprnAndNoticeBoard" | ||
|
||
response = requests.post(url, json=req_data, headers=headers) | ||
|
||
collections_response = response.json() | ||
|
||
collections = [] | ||
|
||
for collection in collections_response["d"]: | ||
collection_data = collection["ServiceHeaders"][0] | ||
bin_type = collection_data["TaskType"] | ||
collection_date = collection_data["Next"] | ||
next_collection = parser.isoparser().isoparse(collection_date) | ||
collections.append((bin_type, next_collection)) | ||
|
||
ordered_data = sorted(collections, key=lambda x: x[1]) | ||
|
||
for item in ordered_data: | ||
dict_data = { | ||
"type": item[0], | ||
"collectionDate": item[1].strftime(date_format), | ||
} | ||
data["bins"].append(dict_data) | ||
|
||
return data |