forked from robbrad/UKBinCollectionData
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: robbrad#656
- Loading branch information
Showing
3 changed files
with
74 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
55 changes: 55 additions & 0 deletions
55
uk_bin_collection/uk_bin_collection/councils/BrecklandCouncil.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 time | ||
|
||
import requests | ||
|
||
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 = "https://www.breckland.gov.uk/apiserver/ajaxlibrary" | ||
|
||
data = { | ||
"id": "1730410741649", | ||
"jsonrpc": "2.0", | ||
"method": "Breckland.Whitespace.JointWasteAPI.GetBinCollectionsByUprn", | ||
"params": {"uprn": user_uprn, "environment": "live"}, | ||
} | ||
# Make the GET request | ||
response = requests.post(URI, json=data) | ||
|
||
# Parse the JSON response | ||
bin_collection = response.json() | ||
|
||
# Loop through each collection in bin_collection | ||
for collection in bin_collection["result"]: | ||
bin_type = collection.get("collectiontype") | ||
collection_date = collection.get("nextcollection") | ||
|
||
dict_data = { | ||
"type": bin_type, | ||
"collectionDate": datetime.strptime( | ||
collection_date, | ||
"%d/%m/%Y %H:%M:%S", | ||
).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