Skip to content

Commit

Permalink
fix: Adding Babergh and Mid Suffolk District Councils
Browse files Browse the repository at this point in the history
fix: #868
fix: #919
  • Loading branch information
m26dvd committed Nov 11, 2024
1 parent 09384a0 commit 581dbc3
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 0 deletions.
14 changes: 14 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
"wiki_name": "Aylesbury Vale Council (Buckinghamshire)",
"wiki_note": "To get the UPRN, please use [FindMyAddress](https://www.findmyaddress.co.uk/search). Returns all published collections in the past, present, future."
},
"BaberghDistrictCouncil": {
"skip_get_url": true,
"house_number": "Monday",
"url": "https://www.babergh.gov.uk",
"wiki_name": "Babergh District Council",
"wiki_note": "Use the House Number field to pass the DAY of the week for your colletions. Monday/Tuesday/Wednesday/Thursday/Friday"
},
"BCPCouncil": {
"skip_get_url": true,
"uprn": "100040810214",
Expand Down Expand Up @@ -988,6 +995,13 @@
"wiki_name": "Midlothian Council",
"wiki_note": "Pass the house name/number wrapped in double quotes along with the postcode parameter."
},
"MidSuffolkDistrictCouncil": {
"skip_get_url": true,
"house_number": "Monday",
"url": "https://www.midsuffolk.gov.uk",
"wiki_name": "Mid Suffolk District Council",
"wiki_note": "Use the House Number field to pass the DAY of the week for your colletions. Monday/Tuesday/Wednesday/Thursday/Friday"
},
"MidSussexDistrictCouncil": {
"house_number": "OAKLANDS, OAKLANDS ROAD RH16 1SS",
"postcode": "RH16 1SS",
Expand Down
132 changes: 132 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/BaberghDistrictCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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")
bindata = {"bins": []}

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

refusestartDate = datetime(2024, 11, 4)
recyclingstartDate = datetime(2024, 11, 11)

offset_days = days_of_week.index(collection_day)

refuse_dates = get_dates_every_x_days(refusestartDate, 14, 28)
recycling_dates = get_dates_every_x_days(recyclingstartDate, 14, 28)

bank_holidays = [
("25/12/2024", 2),
("26/12/2024", 2),
("27/12/2024", 3),
("30/12/2024", 1),
("31/12/2024", 2),
("01/01/2025", 2),
("02/01/2025", 2),
("03/01/2025", 3),
("06/01/2025", 1),
("07/01/2025", 1),
("08/01/2025", 1),
("09/01/2025", 1),
("10/01/2025", 1),
("18/04/2025", 1),
("21/04/2025", 1),
("22/04/2025", 1),
("23/04/2025", 1),
("24/04/2025", 1),
("25/04/2025", 1),
("05/05/2025", 1),
("06/05/2025", 1),
("07/05/2025", 1),
("08/05/2025", 1),
("09/05/2025", 1),
("26/05/2025", 1),
("27/05/2025", 1),
("28/05/2025", 1),
("29/05/2025", 1),
("30/05/2025", 1),
("25/08/2025", 1),
("26/08/2025", 1),
("27/08/2025", 1),
("28/08/2025", 1),
("29/08/2025", 1),
]

for refuseDate in refuse_dates:

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

holiday_offset = next(
(value for date, value in bank_holidays if date == collection_date), 0
)

if holiday_offset > 0:
collection_date = (
datetime.strptime(collection_date, "%d/%m/%Y")
+ timedelta(days=holiday_offset)
).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")

holiday_offset = next(
(value for date, value in bank_holidays if date == collection_date), 0
)

if holiday_offset > 0:
collection_date = (
datetime.strptime(collection_date, "%d/%m/%Y")
+ timedelta(days=holiday_offset)
).strftime("%d/%m/%Y")

dict_data = {
"type": "Recycling 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
@@ -0,0 +1,132 @@
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")
bindata = {"bins": []}

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

refusestartDate = datetime(2024, 11, 11)
recyclingstartDate = datetime(2024, 11, 4)

offset_days = days_of_week.index(collection_day)

refuse_dates = get_dates_every_x_days(refusestartDate, 14, 28)
recycling_dates = get_dates_every_x_days(recyclingstartDate, 14, 28)

bank_holidays = [
("25/12/2024", 2),
("26/12/2024", 2),
("27/12/2024", 3),
("30/12/2024", 1),
("31/12/2024", 2),
("01/01/2025", 2),
("02/01/2025", 2),
("03/01/2025", 3),
("06/01/2025", 1),
("07/01/2025", 1),
("08/01/2025", 1),
("09/01/2025", 1),
("10/01/2025", 1),
("18/04/2025", 1),
("21/04/2025", 1),
("22/04/2025", 1),
("23/04/2025", 1),
("24/04/2025", 1),
("25/04/2025", 1),
("05/05/2025", 1),
("06/05/2025", 1),
("07/05/2025", 1),
("08/05/2025", 1),
("09/05/2025", 1),
("26/05/2025", 1),
("27/05/2025", 1),
("28/05/2025", 1),
("29/05/2025", 1),
("30/05/2025", 1),
("25/08/2025", 1),
("26/08/2025", 1),
("27/08/2025", 1),
("28/08/2025", 1),
("29/08/2025", 1),
]

for refuseDate in refuse_dates:

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

holiday_offset = next(
(value for date, value in bank_holidays if date == collection_date), 0
)

if holiday_offset > 0:
collection_date = (
datetime.strptime(collection_date, "%d/%m/%Y")
+ timedelta(days=holiday_offset)
).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")

holiday_offset = next(
(value for date, value in bank_holidays if date == collection_date), 0
)

if holiday_offset > 0:
collection_date = (
datetime.strptime(collection_date, "%d/%m/%Y")
+ timedelta(days=holiday_offset)
).strftime("%d/%m/%Y")

dict_data = {
"type": "Recycling 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
26 changes: 26 additions & 0 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Arun Council](#arun-council)
- [Ashford Borough Council](#ashford-borough-council)
- [Aylesbury Vale Council (Buckinghamshire)](#aylesbury-vale-council-(buckinghamshire))
- [Babergh District Council](#babergh-district-council)
- [BCP Council](#bcp-council)
- [Barnet Council](#barnet-council)
- [Barnsley Metropolitan Borough Council](#barnsley-metropolitan-borough-council)
Expand Down Expand Up @@ -133,6 +134,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Mid and East Antrim Borough Council](#mid-and-east-antrim-borough-council)
- [Mid Devon Council](#mid-devon-council)
- [Midlothian Council](#midlothian-council)
- [Mid Suffolk District Council](#mid-suffolk-district-council)
- [Mid Sussex District Council](#mid-sussex-district-council)
- [Milton Keynes City Council](#milton-keynes-city-council)
- [Mole Valley District Council](#mole-valley-district-council)
Expand Down Expand Up @@ -340,6 +342,18 @@ Note: To get the UPRN, please use [FindMyAddress](https://www.findmyaddress.co.u

---

### Babergh District Council
```commandline
python collect_data.py BaberghDistrictCouncil https://www.babergh.gov.uk -s -n XX
```
Additional parameters:
- `-s` - skip get URL
- `-n` - house number

Note: Use the House Number field to pass the DAY of the week for your colletions. Monday/Tuesday/Wednesday/Thursday/Friday

---

### BCP Council
```commandline
python collect_data.py BCPCouncil https://online.bcpcouncil.gov.uk/bindaylookup/ -s -u XXXXXXXX
Expand Down Expand Up @@ -1741,6 +1755,18 @@ Note: Pass the house name/number wrapped in double quotes along with the postcod

---

### Mid Suffolk District Council
```commandline
python collect_data.py MidSuffolkDistrictCouncil https://www.midsuffolk.gov.uk -s -n XX
```
Additional parameters:
- `-s` - skip get URL
- `-n` - house number

Note: Use the House Number field to pass the DAY of the week for your colletions. Monday/Tuesday/Wednesday/Thursday/Friday

---

### Mid Sussex District Council
```commandline
python collect_data.py MidSussexDistrictCouncil https://www.midsussex.gov.uk/waste-recycling/bin-collection/ -s -p "XXXX XXX" -n XX -w http://HOST:PORT/
Expand Down

0 comments on commit 581dbc3

Please sign in to comment.