Skip to content

Commit

Permalink
feat: Adding Redcar and Cleveland Council
Browse files Browse the repository at this point in the history
  • Loading branch information
m26dvd committed Feb 5, 2025
1 parent 1b0bdcf commit 32314e6
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
8 changes: 8 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,14 @@
"wiki_name": "Reading Borough Council",
"wiki_note": "Replace XXXXXXXX with your property's UPRN."
},
"RedcarandClevelandCouncil": {
"house_number": "11",
"postcode": "TS10 2RE",
"skip_get_url": true,
"url": "https://www.redcar-cleveland.gov.uk",
"wiki_name": "Redcar and Cleveland Council",
"wiki_note": "Pass the house name/number and postcode in their respective parameters"
},
"RedditchBoroughCouncil": {
"url": "https://redditchbc.gov.uk",
"wiki_command_url_override": "https://redditchbc.gov.uk",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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_postcode = kwargs.get("postcode")
user_paon = kwargs.get("paon")
check_postcode(user_postcode)
check_paon(user_paon)
bindata = {"bins": []}

URI = "https://api.eu.recollect.net/api/areas/RedcarandClevelandUK/services/50006/address-suggest"

params = {
"q": user_postcode,
"locale": "en-GB",
"_": str(int(time.time() * 1000)),
}

# print(params)

# Send GET request
response = requests.get(URI, params=params)

addresses = response.json()

place_id = next(
(
item["place_id"]
for item in addresses
if item.get("name", "").startswith(user_paon)
),
None,
)

# print(addresses)
# print(place_id)

URI = (
f"https://api.eu.recollect.net/api/places/{place_id}/services/50006/events"
)

after = datetime.today()
before = after + timedelta(days=30)

after = after.strftime("%Y-%m-%d")
before = before.strftime("%Y-%m-%d")

# print(after)
# print(before)

params = {
"nomerge": 1,
"hide": "reminder_only",
"after": after,
"before": before,
"locale": "en-GB",
"include_message": "email",
"_": str(int(time.time() * 1000)),
}

# print(params)

# Send GET request
response = requests.get(URI, params=params)

response = response.json()

bin_collection = response["events"]

# print(bin_collection)

# Extract "end_day" and "name"
events = [
(event["end_day"], flag["name"])
for event in bin_collection
for flag in event.get("flags", [])
]

# Print results
for end_day, bin_type in events:

date = datetime.strptime(end_day, "%Y-%m-%d")

dict_data = {
"type": bin_type,
"collectionDate": date.strftime(date_format),
}
bindata["bins"].append(dict_data)

bindata["bins"].sort(
key=lambda x: datetime.strptime(x.get("collectionDate"), date_format)
)

return bindata
14 changes: 14 additions & 0 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Powys Council](#powys-council)
- [Preston City Council](#preston-city-council)
- [Reading Borough Council](#reading-borough-council)
- [Redcar and Cleveland Council](#redcar-and-cleveland-council)
- [Redditch Borough Council](#redditch-borough-council)
- [Reigate and Banstead Borough Council](#reigate-and-banstead-borough-council)
- [Renfrewshire Council](#renfrewshire-council)
Expand Down Expand Up @@ -2672,6 +2673,19 @@ Note: Replace XXXXXXXX with your property's UPRN.

---

### Redcar and Cleveland Council
```commandline
python collect_data.py RedcarandClevelandCouncil https://www.redcar-cleveland.gov.uk -s -p "XXXX XXX" -n XX
```
Additional parameters:
- `-s` - skip get URL
- `-p` - postcode
- `-n` - house number

Note: Pass the house name/number and postcode in their respective parameters

---

### Redditch Borough Council
```commandline
python collect_data.py RedditchBoroughCouncil https://redditchbc.gov.uk -u XXXXXXXX
Expand Down

0 comments on commit 32314e6

Please sign in to comment.