-
-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addin Reno Djurs module and documentation (#2363)
* Addin Reno Djurs module and documentation * Changes as requested * reformatting + ./update_docu_links.py --------- Co-authored-by: 5ila5 <[email protected]>
- Loading branch information
Showing
5 changed files
with
134 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
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
89 changes: 89 additions & 0 deletions
89
custom_components/waste_collection_schedule/waste_collection_schedule/source/renodjurs_dk.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,89 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Reno Djurs" | ||
DESCRIPTION = "Reno Djurs collections for Djursland" | ||
URL = "https://renodjurs.dk" | ||
TEST_CASES = { | ||
"TestCase1": { | ||
"id": "46000", | ||
}, | ||
"TestCase2": { | ||
"id": "45000", | ||
}, | ||
"TestCase3": { | ||
"id": 44000, | ||
}, | ||
} | ||
|
||
ICON_MAP = { | ||
"REST-MAD": "mdi:trash-can", | ||
"PAP-PAPIR": "mdi:newspaper", | ||
"PLAST-GLAS-METAL": "mdi:bottle-wine", | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, id: str | int): | ||
self._id = str(id) | ||
self._api_url = f"https://minside.renodjurs.dk/Ordninger.aspx?id={self._id}" | ||
|
||
def fetch(self): | ||
session = requests.Session() | ||
|
||
entries = [] | ||
|
||
r = session.get(self._api_url) | ||
r.raise_for_status() | ||
soup = BeautifulSoup(r.text, "html.parser") | ||
container = soup.find("table", {"class": "table"}) | ||
rows = container.find_all("tr") | ||
|
||
for row in rows: | ||
cells = row.find_all("td") | ||
if len(cells) <= 4: | ||
continue | ||
|
||
raw_type = cells[1].get_text() | ||
fraktion = "unknown" | ||
icon = None | ||
current_pickup = None | ||
next_pickup = None | ||
|
||
if "rest" in raw_type and "mad" in raw_type: | ||
fraktion = "Rest- og Madaffald" | ||
icon = ICON_MAP.get("REST-MAD") | ||
elif "plast" in raw_type and "glas" in raw_type: | ||
fraktion = "Plast-, Glas- og Metalaffald" | ||
icon = ICON_MAP.get("PLAST-GLAS-METAL") | ||
elif "papir" in raw_type: | ||
fraktion = "Pap- og Papiraffald" | ||
icon = ICON_MAP.get("PAP-PAPIR") | ||
|
||
if cells[3].get_text() is None or cells[3].get_text() == "": | ||
continue | ||
|
||
current_pickup = datetime.strptime(cells[3].get_text(), "%d-%m-%Y").date() | ||
next_pickup = datetime.strptime(cells[4].get_text(), "%d-%m-%Y").date() | ||
|
||
if current_pickup == datetime.now().date(): | ||
entries.append( | ||
Collection( | ||
date=current_pickup, | ||
t=fraktion, | ||
icon=icon, | ||
) | ||
) | ||
|
||
entries.append( | ||
Collection( | ||
date=next_pickup, | ||
t=fraktion, | ||
icon=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,38 @@ | ||
# Reno Djurs I/S | ||
|
||
Support for schedules provided by [Reno Djurs i/s](https://renodjurs.dk/), serving Odder and Skanderborg kommuner, Denmark. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: renodjurs_dk | ||
args: | ||
id: See description | ||
``` | ||
### Configuration Variables | ||
**id** | ||
_(String) (required)_ | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: renodjurs_dk | ||
args: | ||
id: "45000" | ||
``` | ||
## How to get the id | ||
Go to the [Min Side Reno Djurs I/S](https://minside.renodjurs.dk/) page, enter your address. | ||
In the URL (web page address) copy the number after `id=` | ||
|
||
`I.e.` [`https://minside.renodjurs.dk/Ordninger.aspx?id=45000`](https://minside.renodjurs.dk/Ordninger.aspx?id=45000) | ||
|
||
Then it's the `45000` part used in the integration |
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