forked from mampfes/hacs_waste_collection_schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nwleics as source (mampfes#1777)
* Add nwleics as source * reformatting + ./update_docu_links.py * make one test case an Integer --------- Co-authored-by: 5ila5 <[email protected]> Co-authored-by: 5ila5 <[email protected]>
- Loading branch information
1 parent
ee82043
commit e9e52ce
Showing
5 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
56 changes: 56 additions & 0 deletions
56
...m_components/waste_collection_schedule/waste_collection_schedule/source/nwleics_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,56 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from dateutil import parser | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "North West Leicestershire District Council" # Title will show up in README.md and info.md | ||
DESCRIPTION = "Source for www.nwleics.gov.uk services for the city of North West Leicestershire District Council, UK" # Describe your source | ||
URL = "https://nwleics.gov.uk/" # Insert url to service homepage. URL will show up in README.md and info.md | ||
TEST_CASES = { # Insert arguments for test cases to be used by test_sources.py script | ||
"Dunmore": {"uprn": "10002359002"}, | ||
"Station Road": {"uprn": 100030573554}, | ||
} | ||
|
||
API_URL = "https://my.nwleics.gov.uk/location?put=nwl{uprn}&rememberme=0&redirect=%2F" | ||
|
||
|
||
ICON_MAP = { | ||
"Refuse": "mdi:trash-can", | ||
"Garden Waste": "mdi:leaf", | ||
"Yellow Bag": "mdi:recycle", | ||
"Blue Bag": "mdi:recycle", | ||
"Red Box": "mdi:recycle", | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn): | ||
self._uprn = uprn | ||
|
||
def fetch(self): | ||
r = requests.get(API_URL.format(uprn=self._uprn)) | ||
r.raise_for_status() | ||
|
||
soup = BeautifulSoup(r.text, "html.parser") | ||
|
||
refuse = soup.find("ul", {"class": "refuse"}) | ||
li_items = refuse.find_all("li") | ||
|
||
entries = [] | ||
|
||
for li in li_items: | ||
strong_tag = li.find("strong") | ||
a_tag = li.find("a") | ||
|
||
collection_date = parser.parse(strong_tag.contents[0]).date() | ||
bin_type = a_tag.contents[0] | ||
|
||
entries.append( | ||
Collection( | ||
date=collection_date, # Collection date | ||
t=bin_type, # Collection type | ||
icon=ICON_MAP.get(bin_type), # Collection icon | ||
) | ||
) | ||
|
||
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 @@ | ||
# North West Leicestershire District Council | ||
|
||
Source for www.nwleics.gov.uk services for the city of North West Leicestershire District Council, UK | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: nwleics_gov_uk | ||
args: | ||
uprn: UPRN_CODE | ||
``` | ||
### Configuration Variables | ||
**uprn** | ||
*(string) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: nwleics_gov_uk | ||
args: | ||
uprn: "100030573554" | ||
``` | ||
## How to get the source argument | ||
The UPRN code can be found found using https://uprn.uk/ |
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