-
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into dartford
- Loading branch information
Showing
21 changed files
with
730 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 73 additions & 2 deletions
75
custom_components/waste_collection_schedule/translations/de.json
Large diffs are not rendered by default.
Oops, something went wrong.
77 changes: 75 additions & 2 deletions
77
custom_components/waste_collection_schedule/translations/en.json
Large diffs are not rendered by default.
Oops, something went wrong.
75 changes: 73 additions & 2 deletions
75
custom_components/waste_collection_schedule/translations/it.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
..._components/waste_collection_schedule/waste_collection_schedule/source/bridgend_gov_uk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection | ||
|
||
TITLE = "Bridgend County Borough Council" | ||
DESCRIPTION = "Source for bridgend.gov.uk" | ||
URL = "https://www.bridgend.gov.uk/" | ||
TEST_CASES: dict = { | ||
"test_001": {"uprn": "100100479873"}, | ||
"test_002": {"uprn": 10032996088}, | ||
"test_003": {"uprn": "10090813443"}, | ||
} | ||
ICON_MAP: dict = { | ||
"Refuse": "mdi:trash-can", | ||
"Recycling": "mdi:recycle", | ||
} | ||
HEADERS: dict = {"user-agent": "Mozilla/5.0"} | ||
|
||
HOW_TO_GET_ARGUMENTS_DESCRIPTION: dict = { | ||
"en": "an easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details.", | ||
} | ||
PARAM_TRANSLATIONS: dict = { | ||
"en": { | ||
"uprn": "Unique Property Reference Number (UPRN)", | ||
} | ||
} | ||
PARAM_DESCRIPTIONS: dict = { | ||
"en": { | ||
"uprn": "Unique Property Reference Number (UPRN)", | ||
} | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn: str | int): | ||
self._uprn = str(uprn) | ||
|
||
def fetch(self) -> list[Collection]: | ||
s = requests.Session() | ||
r = s.get( | ||
f"https://bridgendportal.azurewebsites.net/property/{self._uprn}", | ||
headers=HEADERS, | ||
) | ||
soup: BeautifulSoup = BeautifulSoup(r.content, "html.parser") | ||
|
||
tds: list = soup.find_all("td", {"class": ["service-name", "next-service"]}) | ||
waste_types: list = tds[0::2] | ||
waste_dates: list = tds[1::2] | ||
|
||
entries: list = [] | ||
for i in range(len(waste_types)): | ||
waste_type = waste_types[i].text.split(" ")[0].replace("\n", "").strip() | ||
waste_date = ( | ||
waste_dates[i] | ||
.text.split(" ")[1] | ||
.replace("\t", "") | ||
.replace("Service\n", "") | ||
.strip() | ||
) | ||
entries.append( | ||
Collection( | ||
date=datetime.strptime(waste_date, "%d/%m/%Y").date(), | ||
t=waste_type, | ||
icon=ICON_MAP.get(waste_type), | ||
) | ||
) | ||
|
||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...omponents/waste_collection_schedule/waste_collection_schedule/source/cumberland_gov_uk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Cumberland Council" | ||
DESCRIPTION = "Source for cumberland.gov.uk services for Cumberland Council, UK." | ||
URL = "https://cumberland.gov.uk" | ||
TEST_CASES = { | ||
"Test_001": {"postcode": "CA28 7QS", "uprn": "100110319463"}, | ||
"Test_002": {"postcode": "CA28 8LG", "uprn": 100110320734}, | ||
"Test_003": {"postcode": "CA28 6SW", "uprn": "10000895390"}, | ||
} | ||
ICON_MAP = { | ||
"Recycling": "mdi:recycle", | ||
"Domestic Waste": "mdi:trash-can", | ||
} | ||
HEADERS = {"user-agent": "Mozilla/5.0"} | ||
API_URLS = { | ||
"TOKEN": "https://waste.cumberland.gov.uk/renderform?t=25&k=E43CEB1FB59F859833EF2D52B16F3F4EBE1CAB6A", | ||
"SCHEDULE": "https://waste.cumberland.gov.uk/renderform/Form", | ||
} | ||
|
||
HOW_TO_GET_ARGUMENTS_DESCRIPTION = { | ||
"en": "An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details.", | ||
} | ||
PARAM_TRANSLATIONS = { | ||
"en": { | ||
"postcode": "Postcode of your property", | ||
"uprn": "Unique Property Reference Number (UPRN)", | ||
} | ||
} | ||
PARAM_DESCRIPTIONS = { | ||
"en": { | ||
"postcode": "Postcode of your property", | ||
"uprn": "Unique Property Reference Number (UPRN)", | ||
} | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, postcode: str, uprn: str | int): | ||
self._postcode: str = str(postcode).upper() | ||
self._uprn: str = str(uprn) | ||
|
||
def fetch(self) -> list[Collection]: | ||
s = requests.Session() | ||
|
||
# Get token | ||
r = s.get( | ||
API_URLS["TOKEN"], | ||
headers=HEADERS, | ||
) | ||
|
||
soup: BeautifulSoup = BeautifulSoup(r.content, "html.parser") | ||
token: str = soup.find("input", {"type": "hidden"}).get("value") | ||
|
||
# get schedule | ||
payload: dict = { | ||
"__RequestVerificationToken": token, | ||
"FF265": f"U{self._uprn}", | ||
"FF265-text": self._postcode, | ||
"FF265lbltxt": "Please select your address", | ||
"FormGuid": "371be01e-1204-428e-bccd-eeacaf7cbfac", | ||
"ObjectTemplateID": "25", | ||
"Trigger": "submit", | ||
"CurrentSectionID": "33", | ||
"TriggerCtl": "", | ||
} | ||
r = s.post( | ||
API_URLS["SCHEDULE"], | ||
headers=HEADERS, | ||
data=payload, | ||
) | ||
|
||
soup = BeautifulSoup(r.content, "html.parser") | ||
schedule: list = soup.find_all("div", {"class": "col"}) | ||
schedule = [item.text for item in schedule[2:] if item.text != ""] | ||
waste_dates: list = schedule[0::2] | ||
waste_types: list = schedule[1::2] | ||
|
||
entries: list = [] | ||
for i in range(0, len(waste_types)): | ||
entries.append( | ||
Collection( | ||
date=datetime.strptime(waste_dates[i], "%A %d %B %Y").date(), | ||
t=waste_types[i].replace(" Collection Service", ""), | ||
icon=ICON_MAP.get( | ||
waste_types[i].replace(" Collection Service", "") | ||
), | ||
) | ||
) | ||
|
||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.