Skip to content

Commit

Permalink
karlsruhe_de add ladeort argument + minor reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Nov 13, 2023
1 parent 50972be commit 1545164
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import datetime
import re

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from bs4 import BeautifulSoup
import re
import datetime
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "City of Karlsruhe"
DESCRIPTION = "Source for City of Karlsruhe."
URL = "https://www.karlsruhe.de/"
TEST_CASES = {
"Östliche Rheinbrückenstraße 1": {
"street": "Östliche Rheinbrückenstraße",
"hnr": 1
"hnr": 1,
},
"Habichtweg 4": {"street": "Habichtweg", "hnr": "4"},
"Machstraße 5": {"street": "Machstraße", "hnr": "5"},
"Bernsteinstraße 10 ladeort 1": {
"street": "Bernsteinstraße",
"hnr": "10",
"ladeort": "1",
},
"Habichtweg 4": {
"street": "Habichtweg",
"hnr": "4"
"Bernsteinstraße 10 ladeort 2": {
"street": "Bernsteinstraße",
"hnr": 10,
"ladeort": 2,
},
"Machstraße 5": {
"street": "Machstraße",
"hnr": "5"
}
}


Expand All @@ -28,22 +33,24 @@
"Bioabfall": "mdi:leaf",
"Papier": "mdi:package-variant",
"Wertstoff": "mdi:recycle",
"Sperrmüllabholung": "mdi:wardrobe"
"Sperrmüllabholung": "mdi:wardrobe",
}


API_URL = "https://web6.karlsruhe.de/service/abfall/akal/akal.php"


class Source:
def __init__(self, street: str, hnr: str | int):
def __init__(self, street: str, hnr: str | int, ladeort: int | None = None):
self._street: str = street
self._hnr: str | int = hnr
self._ladeort: int | None = ladeort

def fetch(self):
args = {
"strasse_n": self._street,
"hausnr": self._hnr,
"ladeort": self._ladeort,
"anzeigen": "anzeigen",
}

Expand All @@ -60,18 +67,18 @@ def fetch(self):

for row in rows:
bin_type = row.find("div", class_="col_3-2")
if bin_type == None:
if bin_type is None:
continue

bin_type = bin_type.contents[0].text.split(",")[0].strip()
if bin_type.endswith(":"):
bin_type = bin_type[:-1].strip()

pickup_col = row.find("div", class_="col_3-3")
if pickup_col == None or not pickup_col.contents:
if pickup_col is None or not pickup_col.contents:
pickup_col = row.find("div", class_="col_4-3")

if pickup_col == None or not pickup_col.contents:
if pickup_col is None or not pickup_col.contents:
continue

for date in re.findall(r"\d{2}\.\d{2}\.\d{4}", pickup_col.text):
Expand Down
20 changes: 20 additions & 0 deletions doc/source/karlsruhe_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ waste_collection_schedule:
args:
street: STRAßE
hnr: "HAUSNUMMER"
ladeort: LADEORT

```
Expand All @@ -22,9 +23,16 @@ waste_collection_schedule:
**hnr**
*(String | Integer) (required)*
**ladeort**
*(String | Integer) (optional)*
only needed for some very limited addresses
## Example
### without `ladeort`

```yaml
waste_collection_schedule:
sources:
Expand All @@ -34,6 +42,18 @@ waste_collection_schedule:
hnr: 1
```

```yaml
waste_collection_schedule:
sources:
- name: karlsruhe_de
args:
street: Bernsteinstraße
hnr: 10
ladeort: 2
```

## How to get the source argument

Find the parameter of your address using [https://web6.karlsruhe.de/service/abfall/akal/akal.php](https://web6.karlsruhe.de/service/abfall/akal/akal.php) and write them exactly like on the web page.

`ladeort` is only required if the website prompts for a "Abholplatz". `ladeort` is the Number of the drop down element behind "Abholplatz" (e.g. 1 for the first element of the drop down menu, 2 for the second item of the drop down menu ...)

0 comments on commit 1545164

Please sign in to comment.