Skip to content

Commit

Permalink
Merge pull request #866 from m26dvd/master
Browse files Browse the repository at this point in the history
feat: Adding London Borough of Ealing
  • Loading branch information
dp247 authored Oct 9, 2024
2 parents 70fda46 + 7b5fc23 commit 36286c4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@
"wiki_name": "Liverpool City Council",
"wiki_note": "Replace XXXXXXXX with your property's UPRN."
},
"LondonBoroughEaling": {
"skip_get_url": true,
"uprn": "12081498",
"url": "https://www.ealing.gov.uk/site/custom_scripts/WasteCollectionWS/home/FindCollection",
"wiki_name": "London Borough Ealing"
},
"LondonBoroughHounslow": {
"skip_get_url": true,
"uprn": "100021577765",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import requests
from requests.structures import CaseInsensitiveDict

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)
data = {"bins": []}

url = "https://www.ealing.gov.uk/site/custom_scripts/WasteCollectionWS/home/FindCollection"

headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/json"

body = {"uprn": user_uprn}
json_data = json.dumps(body)

res = requests.post(url, headers=headers, data=json_data)

if res.status_code != 200:
raise ConnectionRefusedError("Cannot connect to API!")

json_data = res.json()

if "param2" in json_data:
param2 = json_data["param2"]
for service in param2:
Bin_Type = service["Service"]
NextCollectionDate = service["collectionDateString"]
dict_data = {
"type": Bin_Type,
"collectionDate": datetime.strptime(
NextCollectionDate, "%d/%m/%Y"
).strftime(date_format),
}
data["bins"].append(dict_data)

return data

0 comments on commit 36286c4

Please sign in to comment.