mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 02:04:22 +01:00
add source eth_erd_hu (#1344)
This commit is contained in:
@@ -798,6 +798,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
|
||||
- [FKF Budapest](/doc/source/fkf_bp_hu.md) / fkf.hu
|
||||
- [FKF Budaörs](/doc/source/fkf_bo_hu.md) / fkf.hu
|
||||
- [ÉTH (Érd, Diósd, Nagytarcsa, Sóskút, Tárnok)](/doc/source/eth_erd_hu.md) / eth-erd.hu
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import json
|
||||
import requests
|
||||
import datetime
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection
|
||||
|
||||
TITLE = "ÉTH (Érd, Diósd, Nagytarcsa, Sóskút, Tárnok)"
|
||||
DESCRIPTION = "Source script for www.eth-erd.hu"
|
||||
URL = "https://www.eth-erd.hu"
|
||||
COUNTRY = "hu"
|
||||
TEST_CASES = {
|
||||
"Test_1": {
|
||||
"city": "Diósd",
|
||||
"street": "Diófasor",
|
||||
"house_number": 10
|
||||
},
|
||||
"Test_2": {
|
||||
"city": "Érd",
|
||||
"street": "Hordó",
|
||||
"house_number": 3
|
||||
},
|
||||
"Test_3": {
|
||||
"city": "Sóskút"
|
||||
}
|
||||
}
|
||||
|
||||
API_URL = "https://www.eth-erd.hu/trashcalendarget"
|
||||
|
||||
ICON_MAP = {
|
||||
"Kommunális": "mdi:trash-can",
|
||||
"Szelektív": "mdi:recycle",
|
||||
"Zöldhulladék": "mdi:leaf",
|
||||
"Papír": "mdi:newspaper",
|
||||
"Fenyőfa": "mdi:pine-tree",
|
||||
"Üveg": "mdi:glass-fragile",
|
||||
}
|
||||
|
||||
NAME_MAP = {
|
||||
"Kommunális": "Communal",
|
||||
"Szelektív": "Selective",
|
||||
"Zöldhulladék": "Green",
|
||||
"Papír": "Paper",
|
||||
"Fenyőfa": "Pine Tree",
|
||||
"Üveg": "Glass",
|
||||
}
|
||||
|
||||
CITY_MAP = {
|
||||
"diósd": 1,
|
||||
"érd": 2,
|
||||
"nagytarcsa": 822,
|
||||
"sóskút": 3,
|
||||
"tárnok": 4,
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, city: str, street: str = "", house_number: int = 1) -> None:
|
||||
self._city = city
|
||||
self._street = street
|
||||
self._house_number = house_number
|
||||
|
||||
def fetch(self):
|
||||
session = requests.Session()
|
||||
|
||||
city_id = CITY_MAP.get(self._city.lower())
|
||||
if city_id == None: raise Exception("City not found")
|
||||
has_streets = city_id != CITY_MAP["sóskút"]
|
||||
|
||||
if has_streets:
|
||||
r = session.post(
|
||||
API_URL + "streets",
|
||||
data={
|
||||
"sid": city_id
|
||||
},
|
||||
headers={
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
}
|
||||
)
|
||||
r.raise_for_status()
|
||||
streets = json.loads(r.text)["results"]
|
||||
available_streets = [item["text"] for item in streets]
|
||||
try: street_id = [item for item in streets if item.get('text') == self._street][0]["id"]
|
||||
except IndexError: raise Exception("Street not found, available streets: " + ", ".join(available_streets))
|
||||
|
||||
r = session.post(
|
||||
API_URL,
|
||||
data={
|
||||
"wctown": city_id,
|
||||
"wcstreet": street_id,
|
||||
"wchousenumber": self._house_number,
|
||||
} if has_streets else {
|
||||
"wctown": city_id,
|
||||
},
|
||||
headers={
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
}
|
||||
)
|
||||
r.raise_for_status()
|
||||
result: dict = json.loads(r.text)
|
||||
|
||||
entries = []
|
||||
|
||||
for trash_type_id in result["types"]:
|
||||
trash_type = result["types"][trash_type_id]
|
||||
trash_icon = ICON_MAP[trash_type["name"]]
|
||||
trash_name = NAME_MAP[trash_type["name"]]
|
||||
|
||||
for element in result["routelist"][trash_type_id]:
|
||||
entries.append(
|
||||
Collection(
|
||||
date = datetime.datetime.strptime(element, "%Y-%m-%d").date(),
|
||||
t = trash_name,
|
||||
icon = trash_icon,
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
41
doc/source/eth_erd_hu.md
Normal file
41
doc/source/eth_erd_hu.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# ÉTH (Érd, Diósd, Nagytarcsa, Sóskút, Tárnok)
|
||||
|
||||
Support for schedules provided by [ÉTH](https://www.eth-erd.hu/hulladeknaptar), serving Diósd, Érd, Nagytarcsa, Sóskút, Tárnok, HU.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: eth_erd_hu
|
||||
args:
|
||||
city: CITY_NAME
|
||||
street: FULL_STREET_NAME
|
||||
house_number: HOUSE_NUMBER
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**CITY**
|
||||
*(string) (required)*
|
||||
|
||||
**STREET**
|
||||
*(string) (required)*
|
||||
without "utca", "út", etc.
|
||||
not required in Sóskút
|
||||
|
||||
**HOUSE_NUMBER**
|
||||
*(number) (required)*
|
||||
not required in Sóskút
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: eth_erd_hu
|
||||
args:
|
||||
city: Diósd
|
||||
street: Diófasor
|
||||
house_number: 10
|
||||
```
|
||||
Reference in New Issue
Block a user