Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Council Pack 19 #1035

Merged
merged 13 commits into from
Nov 24, 2024
87 changes: 80 additions & 7 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@
"wiki_name": "Chelmsford City Council",
"wiki_note": "Follow the instructions [here](https://www.chelmsford.gov.uk/myhome/) until you get the page listing your address, then copy the entire address text and use that in the house number field."
},
"CheltenhamBoroughCouncil": {
"skip_get_url": true,
"house_number": "Monday",
"postcode": "Week 1",
"url": "https://www.cheltenham.gov.uk",
"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]."
},
"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 Expand Up @@ -723,6 +731,13 @@
"wiki_name": "Flintshire County Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"FolkstoneandHytheDistrictCouncil": {
"skip_get_url": true,
"uprn": "50032097",
"url": "https://www.folkestone-hythe.gov.uk",
"wiki_name": "Folkstone and Hythe District Council",
"wiki_note": "Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN."
},
"ForestOfDeanDistrictCouncil": {
"house_number": "ELMOGAL, PARKEND ROAD, BREAM, LYDNEY",
"postcode": "GL15 6JT",
Expand Down Expand Up @@ -781,6 +796,13 @@
"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)."
},
"HackneyCouncil": {
"house_number": "101",
"postcode": "N16 9AS",
"url": "https://www.hackney.gov.uk",
"wiki_name": "Hackney Council",
"wiki_note": "Pass the postcode and house number in their respective arguments, both wrapped in quotes."
},
"HaltonBoroughCouncil": {
"house_number": "12",
"postcode": "WA7 4HA",
Expand Down Expand Up @@ -879,6 +901,12 @@
"wiki_name": "Islington Council",
"wiki_note": "Replace XXXXXXXX with your UPRN."
},
"KingsLynnandWestNorfolkBC": {
"uprn": "10023636886",
"url": "https://www.west-norfolk.gov.uk/",
"wiki_name": "Kings Lynn and West Norfolk Borough Council",
"wiki_note": "Provide your UPRN. Find your UPRN using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"KingstonUponThamesCouncil": {
"url": "https://waste-services.kingston.gov.uk/waste/2701097",
"wiki_command_url_override": "https://waste-services.kingston.gov.uk/waste/XXXXXXX",
Expand Down Expand Up @@ -984,6 +1012,15 @@
"wiki_name": "London Borough Lambeth",
"wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"LondonBoroughLewisham": {
"postcode": "SE12 9QF",
"skip_get_url": true,
"uprn": "100021954849",
"url": "https://www.lewisham.gov.uk",
"web_driver": "http://selenium:4444",
"wiki_name": "London Borough Lewisham",
"wiki_note": "Pass the UPRN and postcode. To get the UPRN, you can use [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"LondonBoroughRedbridge": {
"postcode": "IG2 6LQ",
"uprn": "10023770353",
Expand Down Expand Up @@ -1095,6 +1132,12 @@
"wiki_name": "Mole Valley District Council",
"wiki_note": "UPRN can only be parsed with a valid postcode."
},
"MorayCouncil": {
"uprn": "28841",
"url": "https://bindayfinder.moray.gov.uk/",
"wiki_name": "Moray Council",
"wiki_note": "Find your property ID by going to (https://bindayfinder.moray.gov.uk), search for your property and extracting the ID from the URL. i.e. (https://bindayfinder.moray.gov.uk/disp_bins.php?id=00028841)"
},
"NeathPortTalbotCouncil": {
"house_number": "2",
"postcode": "SA13 3BA",
Expand Down Expand Up @@ -1392,6 +1435,14 @@
"wiki_command_url_override": "https://www.rotherham.gov.uk/bin-collections?address=XXXXXXXXX&submit=Submit",
"wiki_note": "Replace `XXXXXXXXX` with your UPRN in the URL. You can find your UPRN using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"RoyalBoroughofGreenwich": {
"house_number": "57",
"postcode": "BR7 6DN",
"skip_get_url": true,
"url": "https://www.royalgreenwich.gov.uk",
"wiki_name": "Royal Borough of Greenwich",
"wiki_note": "Provide your house number in the `house_number` parameter and your postcode in the `postcode` parameter."
},
"RugbyBoroughCouncil": {
"postcode": "CV22 6LA",
"skip_get_url": true,
Expand Down Expand Up @@ -1422,6 +1473,13 @@
"wiki_name": "Salford City Council",
"wiki_note": "Provide your UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"SandwellBoroughCouncil": {
"uprn": "10008755549",
"skip_get_url": true,
"url": "https://www.sandwell.gov.uk",
"wiki_name": "Sandwell Borough Council",
"wiki_note": "Pass the UPRN. You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"SeftonCouncil": {
"house_number": "1",
"postcode": "L20 6GG",
Expand Down Expand Up @@ -1537,10 +1595,10 @@
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN."
},
"SouthStaffordshireDistrictCouncil": {
"uprn": "200004523954",
"url": "https://www.sstaffs.gov.uk/where-i-live?uprn=200004523954",
"wiki_name": "South Staffordshire District Council",
"wiki_note": "The URL needs to be `https://www.sstaffs.gov.uk/where-i-live?uprn=<Your_UPRN>`. Replace `<Your_UPRN>` with your UPRN."
"uprn": "200004523954",
"url": "https://www.sstaffs.gov.uk/where-i-live?uprn=200004523954",
"wiki_name": "South Staffordshire District Council",
"wiki_note": "The URL needs to be `https://www.sstaffs.gov.uk/where-i-live?uprn=<Your_UPRN>`. Replace `<Your_UPRN>` with your UPRN."
},
"SouthTynesideCouncil": {
"house_number": "1",
Expand Down Expand Up @@ -1739,6 +1797,14 @@
"wiki_name": "Three Rivers District Council",
"wiki_note": "Provide your UPRN and postcode. Find your UPRN using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"ThurrockCouncil": {
"skip_get_url": true,
"house_number": "Monday",
"postcode": "Round A",
"url": "https://www.thurrock.gov.uk",
"wiki_name": "Thurrock 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 ROUND (wrapped in quotes) for your collections. [Round A/Round B]."
},
"TonbridgeAndMallingBC": {
"postcode": "ME19 4JS",
"skip_get_url": true,
Expand Down Expand Up @@ -1909,11 +1975,11 @@
"wiki_note": "Provide your UPRN. You can find your UPRN using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"WestNorthamptonshireCouncil": {
"postcode": "NN3 2JB",
"uprn": "28056796",
"skip_get_url": true,
"url": "https://www.northampton.gov.uk/info/200084/bins-waste-and-recycling/1602/check-your-collection-day",
"url": "https://www.westnorthants.gov.uk",
"wiki_name": "West Northamptonshire Council",
"wiki_note": "Provide your postcode in the `postcode` parameter."
"wiki_note": "Provide your UPRN. You can find your UPRN using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"WestOxfordshireDistrictCouncil": {
"house_number": "24",
Expand Down Expand Up @@ -2028,6 +2094,13 @@
"wiki_name": "Wyre Council",
"wiki_note": "Provide your UPRN and postcode. Find your UPRN using [FindMyAddress](https://www.findmyaddress.co.uk/search). The postcode should be wrapped in double quotes with a space in the middle."
},
"WyreForestDistrictCouncil": {
"skip_get_url": true,
"house_number": "Monday",
"url": "https://www.wyreforestdc.gov.uk",
"wiki_name": "Wyre Forest District Council",
"wiki_note": "Use the House Number field to pass the DAY of the week for your collections. [Monday/Tuesday/Wednesday/Thursday/Friday/Saturday/Sunday]."
},
"YorkCouncil": {
"skip_get_url": true,
"uprn": "100050535540",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import re
import time

import requests
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.wait import WebDriverWait

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:

collection_day = kwargs.get("paon")
collection_week = kwargs.get("postcode")
bindata = {"bins": []}

days_of_week = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
]

week = ["Week 1", "Week 2"]

offset_days = days_of_week.index(collection_day)
collection_week = week.index(collection_week)

if collection_week == 0:
refusestartDate = datetime(2024, 11, 25)
recyclingstartDate = datetime(2024, 11, 18)
else:
refusestartDate = datetime(2024, 11, 18)
recyclingstartDate = datetime(2024, 11, 25)

refuse_dates = get_dates_every_x_days(refusestartDate, 14, 28)
recycling_dates = get_dates_every_x_days(recyclingstartDate, 14, 28)
food_dates = get_dates_every_x_days(recyclingstartDate, 7, 56)

for refuseDate in refuse_dates:

collection_date = (
datetime.strptime(refuseDate, "%d/%m/%Y") + timedelta(days=offset_days)
).strftime("%d/%m/%Y")

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

for recyclingDate in recycling_dates:

collection_date = (
datetime.strptime(recyclingDate, "%d/%m/%Y")
+ timedelta(days=offset_days)
).strftime("%d/%m/%Y")

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

dict_data = {
"type": "Garden Waste Bin",
"collectionDate": collection_date,
}
bindata["bins"].append(dict_data)

for food_date in food_dates:

collection_date = (
datetime.strptime(food_date, "%d/%m/%Y") + timedelta(days=offset_days)
).strftime("%d/%m/%Y")

dict_data = {
"type": "Food Waste Bin",
"collectionDate": collection_date,
}
bindata["bins"].append(dict_data)

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

return bindata
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ def parse_data(self, page: str, **kwargs) -> dict:
wait = WebDriverWait(driver, 60)
address_entry_field = wait.until(
EC.presence_of_element_located(
(By.XPATH, '//*[@id="combobox-input-19"]')
(By.XPATH, '//*[@id="combobox-input-20"]')
)
)

address_entry_field.send_keys(str(full_address))

address_entry_field = wait.until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="combobox-input-19"]'))
EC.element_to_be_clickable((By.XPATH, '//*[@id="combobox-input-20"]'))
)
address_entry_field.click()
address_entry_field.send_keys(Keys.BACKSPACE)
address_entry_field.send_keys(str(full_address[len(full_address) - 1]))

first_found_address = wait.until(
EC.element_to_be_clickable(
(By.XPATH, '//*[@id="dropdown-element-19"]/ul')
(By.XPATH, '//*[@id="dropdown-element-20"]/ul')
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ def parse_data(self, page: str, **kwargs) -> dict:
# Find each <time> element in the schedule
for entry in soup.find_all("time"):

dict_data = {
"type": entry.find(class_="ScheduleItem").text.strip(),
"collectionDate": datetime.strptime(
entry["datetime"],
"%Y-%m-%d",
).strftime("%d/%m/%Y"),
}
bindata["bins"].append(dict_data)
ScheduleItems = entry.find_all(class_="ScheduleItem")

for ScheduleItem in ScheduleItems:
dict_data = {
"type": ScheduleItem.text.strip(),
"collectionDate": datetime.strptime(
entry["datetime"],
"%Y-%m-%d",
).strftime("%d/%m/%Y"),
}
bindata["bins"].append(dict_data)

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