Skip to content

Commit

Permalink
feat: Adding Cherwell District Council
Browse files Browse the repository at this point in the history
  • Loading branch information
m26dvd committed Feb 6, 2025
1 parent 7b634d7 commit 589af89
Show file tree
Hide file tree
Showing 3 changed files with 93 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 @@ -402,6 +402,12 @@
"wiki_name": "Cheltenham Borough Council",
"wiki_note": "Use the House Number field to pass the DAY of the week for your collections. [Monday/Tuesday/Wednesday/Thursday/Friday]. Use the 'postcode' field to pass the WEEK (wrapped in quotes) for your collections. [Week 1/Week 2]."
},
"CherwellDistrictCouncil": {
"uprn": "100121292407",
"url": "https://www.cherwell.gov.uk",
"wiki_name": "Cherwell District Council",
"wiki_note": "Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN."
},
"CheshireEastCouncil": {
"url": "https://online.cheshireeast.gov.uk/MyCollectionDay/SearchByAjax/GetBartecJobList?uprn=100012791226&onelineaddress=3%20COBBLERS%20YARD,%20SK9%207DZ&_=1689413260149",
"wiki_command_url_override": "https://online.cheshireeast.gov.uk/MyCollectionDay/SearchByAjax/GetBartecJobList?uprn=XXXXXXXX&onelineaddress=XXXXXXXX&_=1689413260149",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from datetime import datetime, timedelta

import requests
from bs4 import BeautifulSoup

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 = f"https://www.cherwell.gov.uk/homepage/129/bin-collection-search?uprn={user_uprn}"

# Make the GET request
response = requests.get(URI)

soup = BeautifulSoup(response.text, "html.parser")

def get_full_date(date_str):
# Get the current year
current_year = datetime.today().year

date_str = remove_ordinal_indicator_from_date_string(date_str)

# Convert the input string to a datetime object (assuming the current year first)
date_obj = datetime.strptime(f"{date_str} {current_year}", "%d %B %Y")

# If the date has already passed this year, use next year
if date_obj < datetime.today():
date_obj = datetime.strptime(
f"{date_str} {current_year + 1}", "%d %B %Y"
)

return date_obj.strftime(date_format) # Return in YYYY-MM-DD format

# print(soup)

div = soup.find("div", class_="bin-collection-results__tasks")

for item in div.find_all("li", class_="list__item"):
# Extract bin type
bin_type_tag = item.find("h3", class_="bin-collection-tasks__heading")
bin_type = (
"".join(bin_type_tag.find_all(text=True, recursive=False)).strip()
if bin_type_tag
else "Unknown Bin"
)

# Extract collection date
date_tag = item.find("p", class_="bin-collection-tasks__date")
collection_date = date_tag.text.strip() if date_tag else "Unknown Date"

dict_data = {
"type": bin_type,
"collectionDate": get_full_date(collection_date),
}
bindata["bins"].append(dict_data)

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

return bindata
12 changes: 12 additions & 0 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Charnwood Borough Council](#charnwood-borough-council)
- [Chelmsford City Council](#chelmsford-city-council)
- [Cheltenham Borough Council](#cheltenham-borough-council)
- [Cherwell District Council](#cherwell-district-council)
- [Cheshire East Council](#cheshire-east-council)
- [Cheshire West and Chester Council](#cheshire-west-and-chester-council)
- [Chesterfield Borough Council](#chesterfield-borough-council)
Expand Down Expand Up @@ -957,6 +958,17 @@ Note: Use the House Number field to pass the DAY of the week for your collection

---

### Cherwell District Council
```commandline
python collect_data.py CherwellDistrictCouncil https://www.cherwell.gov.uk -u XXXXXXXX
```
Additional parameters:
- `-u` - UPRN

Note: Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN.

---

### Cheshire East Council
```commandline
python collect_data.py CheshireEastCouncil https://online.cheshireeast.gov.uk/MyCollectionDay/SearchByAjax/GetBartecJobList?uprn=XXXXXXXX&onelineaddress=XXXXXXXX&_=1689413260149
Expand Down

0 comments on commit 589af89

Please sign in to comment.