Skip to content

Commit

Permalink
Merge branch 'master' into feat/python312
Browse files Browse the repository at this point in the history
  • Loading branch information
robbrad authored Nov 1, 2024
2 parents 04552fb + bd56a38 commit a2c9c2b
Show file tree
Hide file tree
Showing 28 changed files with 1,628 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
python-version: '3.12'

- name: Run image
uses: abatilo/[email protected].0
uses: abatilo/[email protected].1
with:
poetry-version: '1.8.4'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wiki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
python-version: '3.12'

- name: Run image
uses: abatilo/[email protected].0
uses: abatilo/[email protected].1
with:
poetry-version: '1.8.4'

Expand Down
62 changes: 62 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,65 @@
## 0.107.0 (2024-10-31)

### Feat

- Adding Powys Council
- Adding Worcester City Council
- Adding Ards and North Down Council
- Adding East Herts Council
- Adding Ashford Borough Council

### Fix

- WestOxfordshireDistrictCouncil
- South Norfolk Council
- ForestOfDeanDistrictCouncil
- Croydon Council
- South Kesteven District Council
- #647
- #630
- #623
- #586
- #578
- #389

## 0.106.0 (2024-10-28)

### Feat

- Adding Stockton On Tees Council
- Adding Fife Council
- Adding Flintshire County Council

### Fix

- #930
- #933
- #750
- West Berkshire Council
- Southwark Council

## 0.105.1 (2024-10-24)

### Fix

- Refactor Midlothian Council scraper to use house number and postcode

## 0.105.0 (2024-10-21)

### Feat

- Adding Teignbridge Council
- Adding Harborough District Council
- Adding Watford Borough Council
- Adding Coventry City Council

### Fix

- #580
- #888
- #902
- #607

## 0.104.0 (2024-10-20)

### Feat
Expand Down
4 changes: 2 additions & 2 deletions custom_components/uk_bin_collection/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"integration_type": "service",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/robbrad/UKBinCollectionData/issues",
"requirements": ["uk-bin-collection>=0.104.0"],
"version": "0.104.0",
"requirements": ["uk-bin-collection>=0.107.0"],
"version": "0.107.0",
"zeroconf": []
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "uk_bin_collection"
version = "0.104.0"
version = "0.107.0"
description = "Python Lib to collect UK Bin Data"
readme = "README.md"
authors = ["Robert Bradley <[email protected]>"]
Expand Down
99 changes: 94 additions & 5 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"wiki_name": "Adur and Worthing Councils",
"wiki_note": "Replace XXXXXXXX with UPRN. You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"ArdsAndNorthDownCouncil": {
"url": "https://www.ardsandnorthdown.gov.uk",
"wiki_command_url_override": "https://www.ardsandnorthdown.gov.uk",
"uprn": "187136177",
"wiki_name": "Ards and North Down Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"ArmaghBanbridgeCraigavonCouncil": {
"url": "https://www.armaghbanbridgecraigavon.gov.uk/",
"wiki_command_url_override": "https://www.armaghbanbridgecraigavon.gov.uk/",
Expand All @@ -27,6 +34,14 @@
"web_driver": "http://selenium:4444",
"wiki_name": "Arun Council"
},
"AshfordBoroughCouncil": {
"url": "https://ashford.gov.uk",
"wiki_command_url_override": "https://ashford.gov.uk",
"postcode": "TN23 7SP",
"uprn": "100060777899",
"wiki_name": "Ashford Borough Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"AylesburyValeCouncil": {
"skip_get_url": true,
"uprn": "766252532",
Expand Down Expand Up @@ -299,6 +314,12 @@
"wiki_name": "Cornwall Council",
"wiki_note": "Use https://uprn.uk/ to find your UPRN."
},
"CoventryCityCouncil": {
"url": "https://www.coventry.gov.uk/directory-record/56384/abberton-way-",
"wiki_command_url_override": "https://www.coventry.gov.uk/directory_record/XXXXXX/XXXXXX",
"wiki_name": "Coventry City Council",
"wiki_note": "Follow the instructions [here](https://www.coventry.gov.uk/bin-collection-calendar) until you get the page that shows the weekly collections for your address then copy the URL and replace the URL in the command."
},
"CrawleyBoroughCouncil": {
"house_number": "9701076",
"skip_get_url": true,
Expand Down Expand Up @@ -385,6 +406,13 @@
"wiki_name": "East Devon District Council",
"wiki_note": "Replace XXXXXXXX with UPRN."
},
"EastHertsCouncil": {
"house_number": "1",
"postcode": "CM20 2FZ",
"skip_get_url": true,
"url": "https://www.eastherts.gov.uk",
"wiki_name": "East Herts Council"
},
"EastLindseyDistrictCouncil": {
"house_number": "Raf Coningsby",
"postcode": "LN4 4SY",
Expand Down Expand Up @@ -478,6 +506,20 @@
"url": "https://www.fenland.gov.uk/article/13114/",
"wiki_name": "Fenland District Council"
},
"FifeCouncil": {
"url": "https://www.fife.gov.uk",
"wiki_command_url_override": "https://www.fife.gov.uk",
"uprn": "320203521",
"wiki_name": "Fife Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"FlintshireCountyCouncil": {
"url": "https://digital.flintshire.gov.uk",
"wiki_command_url_override": "https://digital.flintshire.gov.uk",
"uprn": "100100213710",
"wiki_name": "Flintshire County Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"ForestOfDeanDistrictCouncil": {
"house_number": "ELMOGAL, PARKEND ROAD, BREAM, LYDNEY",
"postcode": "GL15 6JT",
Expand Down Expand Up @@ -537,6 +579,13 @@
"wiki_name": "Halton Borough Council",
"wiki_note": "Pass the House number and post code"
},
"HarboroughDistrictCouncil": {
"url": "https://www.harborough.gov.uk",
"wiki_command_url_override": "https://www.harborough.gov.uk",
"uprn": "100030489072",
"wiki_name": "Harborough District Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"HaringeyCouncil": {
"skip_get_url": true,
"uprn": "100021203052",
Expand Down Expand Up @@ -741,10 +790,12 @@
"wiki_note": "Pass the house name/number plus the name of the street with the postcode parameter, wrapped in double quotes. Check the address in the web site first. This version will only pick the first SHOW button returned by the search or if it is fully unique. The search is not very predictable (e.g. house number 4 returns 14,24,4,44 etc.)."
},
"MidlothianCouncil": {
"url": "https://www.midlothian.gov.uk/directory_record/92551426/glenesk_bonnyrigg_eh19_3je",
"wiki_command_url_override": "https://www.midlothian.gov.uk/directory_record/XXXXXX/XXXXXX",
"house_number": "52",
"postcode": "EH19 2EB",
"skip_get_url": true,
"url": "https://www.midlothian.gov.uk/info/1054/bins_and_recycling/343/bin_collection_days",
"wiki_name": "Midlothian Council",
"wiki_note": "Follow the instructions [here](https://www.midlothian.gov.uk/info/1054/bins_and_recycling/343/bin_collection_days) until you get the page that shows the weekly collections for your address then copy the URL and replace the URL in the command."
"wiki_note": "Pass the house name/number wrapped in double quotes along with the postcode parameter"
},
"MidSussexDistrictCouncil": {
"house_number": "OAKLANDS, OAKLANDS ROAD RH16 1SS",
Expand Down Expand Up @@ -942,6 +993,14 @@
"web_driver": "http://selenium:4444",
"wiki_name": "Portsmouth City Council"
},
"PowysCouncil": {
"house_number": "LANE COTTAGE",
"postcode": "HR3 5JS",
"skip_get_url": true,
"url": "https://www.powys.gov.uk",
"web_driver": "http://selenium:4444",
"wiki_name": "Powys Council"
},
"PrestonCityCouncil": {
"house_number": "Town Hall",
"postcode": "PR1 2RL",
Expand Down Expand Up @@ -1128,8 +1187,8 @@
"wiki_name": "South Tyneside Council"
},
"SouthwarkCouncil": {
"url": "https://www.southwark.gov.uk/bins/lookup/",
"wiki_command_url_override": "https://www.southwark.gov.uk/bins/lookup/XXXXXXXX",
"url": "https://services.southwark.gov.uk/bins/lookup/",
"wiki_command_url_override": "https://services.southwark.gov.uk/bins/lookup/XXXXXXXX",
"uprn": "200003469271",
"wiki_name": "Southwark Council",
"wiki_note": "Replace XXXXXXXX with UPRN. You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
Expand Down Expand Up @@ -1167,6 +1226,14 @@
"wiki_name": "Stockport Borough Council",
"wiki_note": "Replace XXXXXXXX with UPRN."
},
"StocktonOnTeesCouncil": {
"house_number": "24",
"postcode": "TS20 2RD",
"skip_get_url": true,
"url": "https://www.stockton.gov.uk",
"web_driver": "http://selenium:4444",
"wiki_name": "Stockton On Tees Council"
},
"StokeOnTrentCityCouncil": {
"url": "https://www.stoke.gov.uk/jadu/custom/webserviceLookUps/BarTecWebServices_missed_bin_calendar.php?UPRN=3455121482",
"wiki_command_url_override": "https://www.stoke.gov.uk/jadu/custom/webserviceLookUps/BarTecWebServices_missed_bin_calendar.php?UPRN=XXXXXXXXXX",
Expand Down Expand Up @@ -1229,6 +1296,14 @@
"url": "https://tdcws01.tandridge.gov.uk/TDCWebAppsPublic/tfaBranded/408?utm_source=pressrelease&utm_medium=smposts&utm_campaign=check_my_bin_day",
"wiki_name": "Tandridge District Council"
},
"TeignbridgeCouncil": {
"url": "https://www.google.co.uk",
"wiki_command_url_override": "https://www.google.co.uk",
"uprn": "100040338776",
"web_driver": "http://selenium:4444",
"wiki_name": "Teignbridge Council",
"wiki_note": "Provide Google as the URL as the real URL breaks the integration. You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"TelfordAndWrekinCouncil": {
"skip_get_url": true,
"uprn": "000452015013",
Expand Down Expand Up @@ -1338,6 +1413,13 @@
"wiki_name": "Warwick District Council",
"wiki_note": "Replace XXXXXXXX with UPRN."
},
"WatfordBoroughCouncil": {
"url": "https://www.watford.gov.uk",
"wiki_command_url_override": "https://www.watford.gov.uk",
"uprn": "100080942183",
"wiki_name": "Watford Borough Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"WaverleyBoroughCouncil": {
"house_number": "23",
"postcode": "GU9 9QG",
Expand Down Expand Up @@ -1467,6 +1549,13 @@
"web_driver": "http://selenium:4444",
"wiki_name": "Wokingham Borough Council"
},
"WorcesterCityCouncil": {
"url": "https://www.Worcester.gov.uk",
"wiki_command_url_override": "https://www.Worcester.gov.uk",
"uprn": "100120650345",
"wiki_name": "Worcester City Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"WychavonDistrictCouncil": {
"postcode": "WR3 7RU",
"skip_get_url": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from datetime import datetime

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


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:
# Get and check UPRN
user_uprn = kwargs.get("uprn")
check_uprn(user_uprn)
bindata = {"bins": []}

API_URL = (
"https://collections-ardsandnorthdown.azurewebsites.net/WSCollExternal.asmx"
)

# council seems to always be ARD no matter what the old council was
PAYLOAD = f"""<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getRoundCalendarForUPRN xmlns="http://webaspx-collections.azurewebsites.net/">
<council>ARD</council>
<UPRN>{user_uprn}</UPRN>
<from>Chtml</from>
</getRoundCalendarForUPRN >
</soap:Body>
</soap:Envelope>
"""

r = requests.post(
API_URL,
data=PAYLOAD,
headers={"Content-Type": "text/xml; charset=utf-8"},
)
r.raise_for_status()

# html unescape text
text = (
(r.text.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&"))
.split("<getRoundCalendarForUPRNResult>")[-1]
.split("</getRoundCalendarForUPRNResult>")[0]
)

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

# Initialize dictionary to store bin dates
bin_schedule = {}

# Define regex pattern to capture day and date (e.g., Tue 5 Nov)
date_pattern = re.compile(r"\b\w{3} \d{1,2} \w{3}\b")

current_year = datetime.now().year

# Find each bin collection line, parse date, and add to dictionary
for bin_info in soup.find_all("b"):
bin_type = bin_info.text.strip()
bin_details = bin_info.next_sibling.strip() if bin_info.next_sibling else ""
# Check for "Today" or "Tomorrow"
if "Today" in bin_details:
collection_date = datetime.now().strftime("%a %d %b")
bin_schedule[bin_type] = collection_date
elif "Tomorrow" in bin_details:
collection_date = (datetime.now() + timedelta(days=1)).strftime(
"%a %d %b"
)
bin_schedule[bin_type] = collection_date
else:
# Extract date if it's a full date format
date_match = date_pattern.search(bin_details)
if date_match:
bin_schedule[bin_type] = date_match.group()

# Display the parsed schedule with dates only
for bin_type, collection_date in bin_schedule.items():
date = datetime.strptime(collection_date, "%a %d %b")

if date.month == 1 and datetime.now().month > 1:
date = date.replace(year=current_year + 1)
else:
date = date.replace(year=current_year)

dict_data = {
"type": bin_type,
"collectionDate": date.strftime("%d/%m/%Y"),
}
bindata["bins"].append(dict_data)

bindata["bins"].sort(
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y")
)
return bindata
Loading

0 comments on commit a2c9c2b

Please sign in to comment.