Skip to content

Commit

Permalink
feat: Add Gwynedd Council
Browse files Browse the repository at this point in the history
fix: #1125
  • Loading branch information
m26dvd committed Jan 6, 2025
1 parent 8477933 commit 3511819
Show file tree
Hide file tree
Showing 3 changed files with 72 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 @@ -830,6 +830,12 @@
"wiki_name": "Guildford Council",
"wiki_note": "If the bin day is 'today' then the collectionDate will only show today's date if before 7 AM; else the date will be in 'previousCollectionDate'. To get the UPRN, you will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"GwyneddCouncil": {
"url": "https://diogel.gwynedd.llyw.cymru",
"uprn": "10070350463",
"wiki_name": "Gwynedd Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"HackneyCouncil": {
"house_number": "101",
"postcode": "N16 9AS",
Expand Down
54 changes: 54 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/GwyneddCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import requests
from bs4 import BeautifulSoup, Tag

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://diogel.gwynedd.llyw.cymru/Daearyddol/en/LleDwinByw/Index/{user_uprn}"

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

soup = BeautifulSoup(response.text, "html.parser")
collections_headline = soup.find("h6", text="Next collection dates:")
if not isinstance(collections_headline, Tag):
raise Exception("Could not find collections")
collections = collections_headline.find_next("ul").find_all("li")

for collection in collections:
if not isinstance(collection, Tag):
continue
for p in collection.find_all("p"):
p.extract()

bin_type, date_str = collection.text.strip().split(":")[:2]
bin_type, date_str = bin_type.strip(), date_str.strip()

dict_data = {
"type": bin_type,
"collectionDate": datetime.strptime(date_str, "%A %d/%m/%Y").strftime(
date_format
),
}
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 @@ -116,6 +116,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Gloucester City Council](#gloucester-city-council)
- [Gravesham Borough Council](#gravesham-borough-council)
- [Guildford Council](#guildford-council)
- [Gwynedd Council](#gwynedd-council)
- [Hackney Council](#hackney-council)
- [Halton Borough Council](#halton-borough-council)
- [Harborough District Council](#harborough-district-council)
Expand Down Expand Up @@ -1581,6 +1582,17 @@ Note: If the bin day is 'today' then the collectionDate will only show today's d

---

### Gwynedd Council
```commandline
python collect_data.py GwyneddCouncil https://diogel.gwynedd.llyw.cymru -u XXXXXXXX
```
Additional parameters:
- `-u` - UPRN

Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN.

---

### Hackney Council
```commandline
python collect_data.py HackneyCouncil https://www.hackney.gov.uk -p "XXXX XXX" -n XX
Expand Down

0 comments on commit 3511819

Please sign in to comment.