Skip to content

Commit

Permalink
fix: Adding East Lothian Council
Browse files Browse the repository at this point in the history
  • Loading branch information
m26dvd committed Jan 29, 2025
1 parent 693697f commit 48b66e8
Show file tree
Hide file tree
Showing 3 changed files with 105 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 @@ -636,6 +636,14 @@
"wiki_name": "East Lindsey District Council",
"wiki_note": "Pass the house name/number and postcode in their respective parameters. This parser requires a Selenium webdriver."
},
"EastLothianCouncil": {
"house_number": "Flat 1",
"postcode": "EH21 6QA",
"skip_get_url": true,
"url": "https://eastlothian.gov.uk",
"wiki_name": "East Lothian Council",
"wiki_note": "Pass the house number and postcode in their respective parameters"
},
"EastRenfrewshireCouncil": {
"house_number": "23",
"postcode": "G46 6RG",
Expand Down
83 changes: 83 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/EastLothianCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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_postcode = kwargs.get("postcode")
user_paon = kwargs.get("paon")
check_postcode(user_postcode)
check_paon(user_paon)
bindata = {"bins": []}

URI = "http://collectiondates.eastlothian.gov.uk/ajax/your-calendar/load-streets-spring-2024.asp"

payload = {
"postcode": user_postcode,
}

headers = {
"Referer": "http://collectiondates.eastlothian.gov.uk/your-calendar",
"User-Agent": "Mozilla/5.0",
}

# Make the GET request
response = requests.get(URI, headers=headers, params=payload)

# Parse the HTML with BeautifulSoup
soup = BeautifulSoup(response.text, "html.parser")

# Find the select dropdown
select = soup.find("select", id="SelectStreet")

# Find the option that contains "Flat 1"
address = select.find("option", string=lambda text: text and user_paon in text)

URI = "http://collectiondates.eastlothian.gov.uk/ajax/your-calendar/load-recycling-summer-2024.asp"

payload = {
"id": address["value"],
}

# Make the GET request
response = requests.get(URI, headers=headers, params=payload)

# Parse the HTML with BeautifulSoup
soup = BeautifulSoup(response.text, "html.parser")

# Extract collection details
calendar_items = soup.find_all("div", class_="calendar-item")
for item in calendar_items:
waste_label = item.find("div", class_="waste-label").text.strip()
waste_value = item.find("div", class_="waste-value").find("h4").text.strip()

try:
collection_date = datetime.strptime(
remove_ordinal_indicator_from_date_string(waste_value),
"%A %d %B %Y",
)
except ValueError:
continue

dict_data = {
"type": waste_label.replace(" is:", ""),
"collectionDate": collection_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 @@ -93,6 +93,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [East Devon District Council](#east-devon-district-council)
- [East Herts Council](#east-herts-council)
- [East Lindsey District Council](#east-lindsey-district-council)
- [East Lothian Council](#east-lothian-council)
- [East Renfrewshire Council](#east-renfrewshire-council)
- [East Riding Council](#east-riding-council)
- [East Staffordshire Borough Council](#east-staffordshire-borough-council)
Expand Down Expand Up @@ -1308,6 +1309,19 @@ Note: Pass the house name/number and postcode in their respective parameters. Th

---

### East Lothian Council
```commandline
python collect_data.py EastLothianCouncil https://eastlothian.gov.uk -s -p "XXXX XXX" -n XX
```
Additional parameters:
- `-s` - skip get URL
- `-p` - postcode
- `-n` - house number

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

---

### East Renfrewshire Council
```commandline
python collect_data.py EastRenfrewshireCouncil https://eastrenfrewshire.gov.uk/ -s -p "XXXX XXX" -n XX -w http://HOST:PORT/
Expand Down

0 comments on commit 48b66e8

Please sign in to comment.