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.
- Loading branch information
Showing
4 changed files
with
83 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
49 changes: 49 additions & 0 deletions
49
...omponents/waste_collection_schedule/waste_collection_schedule/source/northlincs_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,49 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "North Lincolnshire Council" | ||
DESCRIPTION = "Source for northlincs.gov.uk services for North Lincolnshire Council, UK." | ||
URL = "https://www.northlincs.gov.uk" | ||
TEST_CASES = { | ||
"Test_001": {"uprn": "100050200824"}, | ||
"Test_002": {"uprn": "100050188326"}, | ||
"Test_003": {"uprn": 100050199446}, | ||
"Test_004": {"uprn": 100050196285}, | ||
} | ||
ICON_MAP = { | ||
"Plastic and cardboard wheeled bin": "mdi:recycle", | ||
"Blue kerbside box - paper": "mdi:package-variant", | ||
"Brown garden waste wheeled bin": "mdi:leaf", | ||
"Textiles Bag": "mdi:sack", | ||
"Green kerbside box - cans, glass and aluminium foil": "mdi:glass-fragile", | ||
"General waste wheeled bin": "mdi:trash-can", | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, uprn): | ||
self._uprn = str(uprn) | ||
|
||
def fetch(self): | ||
r = requests.get( | ||
f"https://m.northlincs.gov.uk/collection_dates/{self._uprn}/0/6?_=1546855781728&format=json") | ||
r.raise_for_status() | ||
|
||
entries = [] | ||
|
||
for collection in r.json()["Collections"]: | ||
date_string = collection["CollectionDate"].replace("/Date(", "").replace(")/", "")[:10] | ||
date = datetime.fromtimestamp(int(date_string)).date() | ||
waste_type = collection["BinCodeDescription"] | ||
entries.append( | ||
Collection( | ||
date=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# North Lincolnshire Council | ||
|
||
Support for schedules provided by [North Lincolnshire Council ](https://www.northlincs.gov.uk/), UK. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: northlincs_gov_uk | ||
args: | ||
uprn: UPRN_CODE | ||
``` | ||
### Configuration Variables | ||
**uprn** | ||
*(string) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: northlincs_gov_uk | ||
args: | ||
uprn: "100050200824" | ||
``` | ||
## How to get the source argument | ||
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. |
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