-
-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
1 deletion.
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
58 changes: 58 additions & 0 deletions
58
...m_components/waste_collection_schedule/waste_collection_schedule/source/horsham_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,58 @@ | ||
import logging | ||
from datetime import datetime | ||
from waste_collection_schedule import Collection | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
TITLE = "Horsham District Council" | ||
DESCRIPTION = "Source script for Horsham District Council" | ||
URL = "https://www.horsham.gov.uk" | ||
TEST_CASES = { | ||
"Blackthorn Avenue - number": {"uprn": 10013792881}, | ||
"Blackthorn Avenue - string": {"uprn": "10013792881"} | ||
} | ||
API_URL = "https://satellite.horsham.gov.uk/environment/refuse/cal_details.asp" | ||
ICON_MAP = { | ||
"Refuse Bin for Non-Recycling": "mdi:trash-can", | ||
"Blue-Top Bin for Recycling": "mdi:recycle", | ||
"Brown-Top Bin for Garden Waste": "mdi:leaf", | ||
} | ||
HEADERS = { | ||
"user-agent": "Mozilla/5.0", | ||
} | ||
_LOGGER = logging.getLogger(__name__) | ||
|
||
class Source: | ||
def __init__(self, uprn: str): | ||
self._uprn = str(uprn) | ||
|
||
def fetch(self): | ||
entries = [] | ||
|
||
r = requests.post( | ||
API_URL, | ||
data={"uprn": self._uprn}, | ||
) | ||
|
||
soup = BeautifulSoup(r.text, features="html.parser") | ||
results = soup.find_all("tr") | ||
|
||
for result in results: | ||
result_row = result.find_all("td") | ||
if len(result_row) == 0: # This removes the first header row, or any rows with no data | ||
continue | ||
else: | ||
date = datetime.strptime(result_row[1].text, "%d/%m/%Y").date() # Pull out the rows date | ||
|
||
collection_text = result_row[2].text.replace(u'\xa0', u' ') # This is to remove a non-blanking space | ||
collection_items = collection_text.split("AND") # Sometimes there will be multiple bins, split with the word AND | ||
for collection_type in collection_items: | ||
entries.append( | ||
Collection( | ||
date=date, | ||
t=collection_type.strip(), # Strip added to remove trailing white space | ||
icon=ICON_MAP[collection_type.strip()] # Strip added to remove trailing white space | ||
) | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Horsham District Council | ||
|
||
Support for schedules provided by [Horsham District Council](https://www.horsham.gov.uk/waste-recycling-and-bins/household-bin-collections/check-your-bin-collection-day). | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: horsham_gov_uk | ||
args: | ||
uprn: UPRN_CODE | ||
``` | ||
### Configuration Variables | ||
**uprn** | ||
_(string) (required)_ | ||
## Example using UPRN | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: horsham_gov_uk | ||
args: | ||
uprn: "10013792881" | ||
``` | ||
## How to get the source argument | ||
An easy way to find your Unique Property Reference Number (UPRN) is by going to <https://www.findmyaddress.co.uk/> and entering in your address details. |
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