Skip to content

Commit

Permalink
Merge pull request #50 from dp247/EastDevonDC
Browse files Browse the repository at this point in the history
Add East Devon District Council
  • Loading branch information
robbrad authored Jul 24, 2022
2 parents 96203a4 + 8015a35 commit 1f70f4f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions scripts/councils/EastDevonDC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from bs4 import BeautifulSoup
from get_bin_data import AbstractGetBinDataClass
from datetime import datetime

import pandas as pd
import re


class CouncilClass(AbstractGetBinDataClass):
"""
Concrete classes have to implement all abstract operations of the
baseclass. They can also override some
operations with a default implementation.
"""

def parse_data(self, page: str) -> dict:
# Make a BS4 object
soup = BeautifulSoup(page.text, features="html.parser")
soup.prettify()

data = {"bins": []}
month_class_name = 'class="eventmonth"'
regular_collection_class_name = "collectiondate regular-collection"
holiday_collection_class_name = "collectiondate bankholiday-change"
regex_string = "[^0-9]"

calendar_collection = soup.find("ol", {"class": "nonumbers news collections"})
calendar_list = calendar_collection.find_all("li")
current_month = ""
current_year = ""

for element in calendar_list:
element_tag = str(element)
if month_class_name in element_tag:
current_month = datetime.strptime(element.text, "%B %Y").strftime("%m")
current_year = datetime.strptime(element.text, "%B %Y").strftime("%Y")
elif regular_collection_class_name in element_tag:
week_value = element.find_next("span", {"class": f"{regular_collection_class_name}"})
day_of_week = re.sub(regex_string, "", week_value.text).strip()
collection_date = datetime(int(current_year), int(current_month), int(day_of_week)).strftime("%d/%m/%Y")
collections = week_value.find_next_siblings("span")
for item in collections:
x = item.text
bin_type = item.text.strip()
if len(bin_type) > 1:
dict_data = {
"type": bin_type,
"collectionDate": collection_date,
}
data["bins"].append(dict_data)
elif holiday_collection_class_name in element_tag:
week_value = element.find_next("span", {"class": f"{holiday_collection_class_name}"})
day_of_week = re.sub(regex_string, "", week_value.text).strip()
collection_date = datetime(int(current_year), int(current_month), int(day_of_week)).strftime("%d/%m/%Y")
collections = week_value.find_next_siblings("span")
for item in collections:
x = item.text
bin_type = item.text.strip()
if len(bin_type) > 1:
dict_data = {
"type": bin_type + " (bank holiday replacement)",
"collectionDate": collection_date,
}
data["bins"].append(dict_data)
return data
1 change: 1 addition & 0 deletions tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"CardiffCouncil": "https://www.cardiff.gov.uk/ENG/resident/Rubbish-and-recycling/When-are-my-bins-collected/Pages/default.aspx",
"chelmsford_city_council": "100022887131",
"CheshireEastCouncil": "https://online.cheshireeast.gov.uk/MyCollectionDay/SearchByAjax/GetBartecJobList?uprn=100012791226&onelineaddress=3%20COBBLERS%20YARD,%20SK9%207DZ&_=1621149987573",
"EastDevonDC": "https://eastdevon.gov.uk/recycling-and-waste/recycling-and-waste-information/when-is-my-bin-collected/future-collections-calendar/?UPRN=XXXXXXXX",
"HuntingdonDistrictCouncil": "http://www.huntingdonshire.gov.uk/refuse-calendar/10012048679",
"LeedsCityCouncil": "https://www.leeds.gov.uk/residents/bins-and-recycling/check-your-bin-day",
"NELincs": "https://www.nelincs.gov.uk/refuse-collection-schedule/?uprn=XXXXXXXX&view=timeline",
Expand Down

0 comments on commit 1f70f4f

Please sign in to comment.