mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 02:04:22 +01:00
Add source: Kiertokapula FI (#2091)
* Create kiertokapula_fi.py * Create kiertokapula_fi.md * Small fixes * Improvement to code * reformatting * add Finland to md files + ./update_docu_links.py --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
@@ -17,7 +17,7 @@ repos:
|
||||
hooks:
|
||||
- id: codespell
|
||||
args:
|
||||
- --ignore-words-list=hass,alot,datas,dof,dur,farenheit,hist,iff,ines,ist,lightsensor,mut,nd,pres,referer,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing,Adresse,termine,adresse,oder,alle,assistent,hart,marz,worthing,linz,celle,vor
|
||||
- --ignore-words-list=hass,alot,datas,dof,dur,farenheit,hist,iff,ines,ist,lightsensor,mut,nd,pres,referer,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing,Adresse,termine,adresse,oder,alle,assistent,hart,marz,worthing,linz,celle,vor,leibnitz
|
||||
- --skip="./.*,*.csv,*.json"
|
||||
- --quiet-level=2
|
||||
exclude_types: [csv, json]
|
||||
|
||||
@@ -511,6 +511,12 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [RenoWeb](/doc/source/renoweb_dk.md) / renoweb.dk
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Finland</summary>
|
||||
|
||||
- [Kiertokapula Finland](/doc/source/kiertokapula_fi.md) / kiertokapula.fi
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>France</summary>
|
||||
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "Kiertokapula Finland"
|
||||
DESCRIPTION = "Schedule for kiertokapula FI"
|
||||
URL = "https://www.kiertokapula.fi"
|
||||
TEST_CASES = {
|
||||
"Test1": {
|
||||
"bill_number": "!secret kiertonkapula_fi_bill_number",
|
||||
"password": "!secret kiertonkapula_fi_bill_password",
|
||||
}
|
||||
}
|
||||
ICON_MAP = {
|
||||
"SEK": "mdi:trash-can",
|
||||
"MUO": "mdi:delete-variant",
|
||||
"KAR": "mdi:package-variant",
|
||||
"LAS": "mdi:glass-wine",
|
||||
"MET": "mdi:tools",
|
||||
"BIO": "mdi:leaf",
|
||||
}
|
||||
NAME_DEF = {
|
||||
"SEK": "Sekajäte",
|
||||
"MUO": "Muovi",
|
||||
"KAR": "Kartonki",
|
||||
"LAS": "Lasi",
|
||||
"MET": "Metalli",
|
||||
"BIO": "Bio",
|
||||
}
|
||||
API_URL = "https://asiakasnetti.kiertokapula.fi/kiertokapula"
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(
|
||||
self,
|
||||
bill_number,
|
||||
password,
|
||||
):
|
||||
self._bill_number = bill_number
|
||||
self._password = password
|
||||
|
||||
def fetch(self):
|
||||
session = requests.Session()
|
||||
session.headers.update({"X-Requested-With": "XMLHttpRequest"})
|
||||
session.get(API_URL)
|
||||
|
||||
# sign in
|
||||
r = session.post(
|
||||
API_URL + "/j_acegi_security_check?target=2",
|
||||
data={
|
||||
"j_username": self._bill_number,
|
||||
"j_password": self._password,
|
||||
"remember-me": "false",
|
||||
},
|
||||
)
|
||||
r.raise_for_status()
|
||||
|
||||
# get customer info
|
||||
|
||||
r = session.get(API_URL + "/secure/get_customer_datas.do")
|
||||
r.raise_for_status()
|
||||
data = r.json()
|
||||
|
||||
entries = []
|
||||
|
||||
for estate in data.values():
|
||||
for customer in estate:
|
||||
r = session.get(
|
||||
API_URL + "/secure/get_services_by_customer_numbers.do",
|
||||
params={"customerNumbers[]": customer["asiakasnro"]},
|
||||
)
|
||||
r.raise_for_status()
|
||||
data = r.json()
|
||||
for service in data:
|
||||
if service["tariff"].get("productgroup", "PER") == "PER":
|
||||
continue
|
||||
next_date_str = None
|
||||
if (
|
||||
"ASTSeurTyhj" in service
|
||||
and service["ASTSeurTyhj"] is not None
|
||||
and len(service["ASTSeurTyhj"]) > 0
|
||||
):
|
||||
next_date_str = service["ASTSeurTyhj"]
|
||||
elif (
|
||||
"ASTNextDate" in service
|
||||
and service["ASTNextDate"] is not None
|
||||
and len(service["ASTNextDate"]) > 0
|
||||
):
|
||||
next_date_str = service["ASTNextDate"]
|
||||
|
||||
if next_date_str is None:
|
||||
continue
|
||||
|
||||
next_date = datetime.strptime(next_date_str, "%Y-%m-%d").date()
|
||||
entries.append(
|
||||
Collection(
|
||||
date=next_date,
|
||||
t=service.get(
|
||||
"ASTNimi",
|
||||
NAME_DEF.get(service["tariff"]["productgroup"], "N/A"),
|
||||
),
|
||||
icon=ICON_MAP.get(service["tariff"]["productgroup"]),
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
28
doc/source/kiertokapula_fi.md
Normal file
28
doc/source/kiertokapula_fi.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Kiertokapula Finland
|
||||
|
||||
Support for upcoming pick ups provided by [Kiertokapula self-service portal](https://asiakasnetti.kiertokapula.fi/).
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: kiertokapula_fi
|
||||
args:
|
||||
bill_number: "YOUR_BILL_NUMBER"
|
||||
password: "YOUR_PASSWORD"
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**bill_number**
|
||||
*(string) (required)*
|
||||
|
||||
**password**
|
||||
*(string) (required)*
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
**You need to have a registered account in Kiertokapula's self-service portal!**
|
||||
To register one, you need to get your customer number from your bills, and password is by default your home address.
|
||||
System will prompt you a password change, after you've done it, you have now registered your user and it's ready to be configured here.
|
||||
@@ -491,6 +491,10 @@ COUNTRYCODES = [
|
||||
"code": "fr",
|
||||
"name": "France",
|
||||
},
|
||||
{
|
||||
"code": "fi",
|
||||
"name": "Finland",
|
||||
},
|
||||
]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user