Skip to content

Commit

Permalink
move poznan_pl to its own source
Browse files Browse the repository at this point in the history
sepan_remodis_pl stopped supporting Poznan
  • Loading branch information
5ila5 committed Jun 27, 2024
1 parent caddefc commit 94e93fd
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Bydgoszcz Pronatura](/doc/source/pronatura_bydgoszcz_pl.md) / pronatura.bydgoszcz.pl
- [Ecoharmonogram](/doc/source/ecoharmonogram_pl.md) / ecoharmonogram.pl
- [Gmina Miękinia](/doc/source/gmina_miekinia_pl.md) / api.skycms.com.pl
- [Poznań](/doc/source/poznan_pl.md) / poznan.pl/mim/odpady
- [Poznań/Koziegłowy/Objezierze/Oborniki](/doc/source/sepan_remondis_pl.md) / sepan.remondis.pl
- [Warsaw](/doc/source/warszawa19115_pl.md) / warszawa19115.pl
- [Wrocław](/doc/source/ekosystem_wroc_pl.md) / ekosystem.wroc.pl
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import datetime
import logging
import re

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

TITLE = "Poznań"
DESCRIPTION = "Source for Poznań city garbage collection"
URL = "https://www.poznan.pl/mim/odpady"
TEST_CASES = {
"Street Name": {
"street_name": "ŚWIĘTY MARCIN",
"street_number": "1",
},
}

_LOGGER = logging.getLogger(__name__)


API_URL = "https://www.poznan.pl/mim/odpady/harmonogramy.html"

ICON_MAP = {
1: "mdi:trash-can",
2: "mdi:recycle",
3: "mdi:recycle",
4: "mdi:recycle",
5: "mdi:recycle",
6: "mdi:recycle",
7: "mdi:trash-can",
}


class Source:
def __init__(self, street_name: str, street_number: str | int):
self._street_name = street_name.upper()
self._street_number = str(street_number).upper()

def fetch(self) -> list[Collection]:
data = {
"action": "search",
"co": "waste_schedule",
"ws_street": self._street_name,
"ws_number": self._street_number,
}

r = requests.post(f"{API_URL}", data)
r.raise_for_status()

# Fix their broken html table
fixed_text = re.sub(r"</td>\s*<tr>\s*<tr>\s*<td", "</td></tr><tr><td", r.text)
fixed_text = re.sub(
r"</th>\s*<tr>\s*<tr>\s*<td", "</td></tr><tr><td", fixed_text
)

soup = BeautifulSoup(fixed_text, "html.parser")

table = soup.find("table")
if not isinstance(table, Tag):
raise Exception("Invalid address")

year = datetime.date.today().year

# find all non empty tr's
trs = [
tr for tr in table.find_all("tr") if isinstance(tr, Tag) and tr.find_all()
]
entries = []
name_map = [th.text.strip() for th in table.find_all("th")]

for row_index, row in enumerate(trs):
if row_index == 0 or row_index > 12:
continue
for cell_index, cell in enumerate(row.find_all("td")):
if (
cell_index == 0
or not isinstance(cell, Tag)
or not cell.text.strip()
):
continue

for day in cell.text.split(","):
day = day.strip()
entries.append(
Collection(
datetime.date(year, row_index, int(day)),
name_map[cell_index],
ICON_MAP[cell_index],
)
)

return entries
40 changes: 40 additions & 0 deletions doc/source/poznan_pl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Poznań

Support for schedules provided by [Poznań](https://poznan.pl).

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: poznan_pl
args:
street_name: Święty Marcin
street_number: 1
```
### Configuration Variables
**street_address**
*(string) (required)*
**street_number**
*(string)(required)*
All arguments must be provided.
## Example
```yaml
waste_collection_schedule:
sources:
- name: poznan_pl
args:
street_name: Święty Marcin
street_number: 1
```
## How to get the source arguments
You have to provide your street name and house number (eg 1 or 7/3).
You can check if your address is covered by SepanRemondis provider at page [poznan.pl](https://www.poznan.pl/mim/odpady/harmonogramy.html)
1 change: 0 additions & 1 deletion doc/source/sepan_remondis_pl.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SepanRemondis

Support for schedules provided by [SepanRemondis](https://sepan.remondis.pl/harmonogram/) for cities:
-Poznań
-Objezierze
-Oborniki
-Koziegłowy
Expand Down
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| Netherlands | ACV Group, Alpen an den Rijn, Area Afval, Avalex, Avri, Bar Afvalbeheer, Circulus, Cyclus NV, Dar, Den Haag, GAD, Gemeente Almere, Gemeente Berkelland, Gemeente Cranendonck, Gemeente Hellendoorn, Gemeente Lingewaard, Gemeente Meppel, Gemeente Middelburg + Vlissingen, Gemeente Peel en Maas, Gemeente Schouwen-Duiveland, Gemeente Sudwest-Fryslan, Gemeente Venray, Gemeente Voorschoten, Gemeente Waalre, Gemeente Westland, HVC Groep, Meerlanden, Mijn Blink, PreZero, Purmerend, RAD BV, Reinis, Spaarnelanden, Twente Milieu, Waardlanden, Ximmio, ZRD, Ôffalkalinder van Noardeast-Fryslân & Dantumadiel |
| New Zealand | Auckland Council, Christchurch City Council, Dunedin District Council, Gore, Invercargill & Southland, Hamilton City Council, Horowhenua District Council, Hutt City Council, Tauranga City Council, Waipa District Council, Wellington City Council |
| Norway | BIR (Bergensområdets Interkommunale Renovasjonsselskap), IRiS, Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Sandnes Kommune, Stavanger Kommune, Trondheim |
| Poland | Bydgoszcz Pronatura, Ecoharmonogram, Gmina Miękinia, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw, Wrocław |
| Poland | Bydgoszcz Pronatura, Ecoharmonogram, Gmina Miękinia, Poznań, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw, Wrocław |
| Slovenia | Moji odpadki, Ljubljana |
| Sweden | Affärsverken, Gästrike Återvinnare, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Lund Waste Collection, North / Middle Bohuslän - Rambo AB, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, Uppsala Vatten och Avfall AB, VA Syd Sophämntning, VIVAB Sophämtning |
| Switzerland | A-Region, Alchenstorf, Andwil, Appenzell, Berg, Bühler, Canton of Zürich, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Münsingen BE, Switzerland, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden |
Expand Down

0 comments on commit 94e93fd

Please sign in to comment.