-
-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added staffordbc_gov_uk source for Stafford Borough Council. Unfortunately we can only scrape the next collection date. * Added staffordbc_gov_uk source for Stafford Borough Council. * Added staffordbc_gov_uk source for Stafford Borough Council.
- Loading branch information
Showing
4 changed files
with
91 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
46 changes: 46 additions & 0 deletions
46
...omponents/waste_collection_schedule/waste_collection_schedule/source/staffordbc_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,46 @@ | ||
from datetime import datetime | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Stafford Borough Council" | ||
DESCRIPTION = "Source for bin collection services for Stafford Borough Council, UK." | ||
URL = "https://www.staffordbc.gov.uk/" | ||
TEST_CASES = { | ||
"domestic": {"uprn": "100031780029"}, | ||
} | ||
|
||
API_URL = "https://www.staffordbc.gov.uk/address/" | ||
|
||
ICON_MAP = { | ||
"Blue bin": "mdi:recycle", | ||
"Brown bin": "mdi:leaf", | ||
"Green bin": "mdi:trash-can", | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn): | ||
self._uprn = uprn | ||
|
||
def fetch(self): | ||
req = requests.get( | ||
f"https://www.staffordbc.gov.uk/address/{self._uprn}" | ||
) | ||
|
||
soup = BeautifulSoup(req.content, "html.parser") | ||
|
||
greenbin = soup.find_all('td')[5] | ||
bluebin = soup.find_all('td')[7] | ||
|
||
entries = [Collection( | ||
date=datetime.strptime(greenbin.text.strip(), "%a %d %b %Y").date(), # Collection date | ||
t="Green Bin", # Collection type | ||
icon=ICON_MAP.get("Green bin"), # Collection icon | ||
), Collection( | ||
date=datetime.strptime(bluebin.text.strip(), "%a %d %b %Y").date(), # Collection date | ||
t="Blue Bin", # Collection type | ||
icon=ICON_MAP.get("Blue bin"), # Collection icon | ||
)] # List that holds collection schedule | ||
|
||
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,43 @@ | ||
# Stafford Borough Council | ||
|
||
Support for schedules provided by [Stafford Borough Council](https://www.staffordbc.gov.uk/) | ||
|
||
# Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: staffordbc_gov_uk | ||
args: | ||
uprn: UPRN_CODE | ||
``` | ||
### Configuration Variables | ||
**uprn**<br> | ||
*(string) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: stafford_gov_uk | ||
args: | ||
uprn: "100031780029" | ||
``` | ||
## How to get the source argument | ||
The UPRN code can be found in the page by entering your postcode on the | ||
[Stafford Borough Council 'About My Area'](https://www.staffordbc.gov.uk/about-my-area) page | ||
Enter your postcode and then select your house from the list, then the UPRN is the final part of | ||
the URL that you are re-directed to. | ||
For example, for post-code ST16 3ES, house number 6, you are re-directed to | ||
https://www.staffordbc.gov.uk/address/100031780029 | ||
The UPRN is 100031780029 |
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