Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blisko source #3011

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Add blisko source #3011

wants to merge 8 commits into from

Conversation

btaczala
Copy link

No description provided.

doc/source/blisko.md Outdated Show resolved Hide resolved
@5ila5
Copy link
Collaborator

5ila5 commented Nov 11, 2024

I do not like that you need to provide ids you need to obtain yourself.
It looks like the cityId, streetId, and houseId are pretty easy to get via the script (https://gateway.sisms.pl/akun/api/owners/{ownerID}/towns/list, https://gateway.sisms.pl/akun/api/owners/{ownerID}/streets/list?townId={formattedTOWN_ID} and https://gateway.sisms.pl/akun/api/owners/112/streetAddresses/list?streetId={formattedSTREET_ID})

You could then hardcode a list of ownerIDs to select from or provide your own (the edpevent_se source does basically the same).

And you can then add them to EXTRA_INFO so they show up in the README and source selection This way users can just search for their area and have an easy way to search for their region

I found some IDs to use:

List of regions I found
  • 39 Gmina Topólka
  • 40 Gmina Strzelin
  • 42 Gmina Reda
  • 44 Gmina Rumia
  • 45 [TEST] Gmina Kuźnica
  • 51 Gmina Złoty Stok
  • 61 Klient Szablonowy - Karty Usług
  • 73 Gmina Wieluń
  • 75 Gmina Łęczyce
  • 77 Gmina Kolbudy
  • 78 Gmina Polanica-Zdrój
  • 81 Gmina Wisznia Mała
  • 82 Polkowice
  • 83 Gmina Cedry Wielkie
  • 84 Gmina i Miasto Nowe Skalmierzyce
  • 85 Gmina Chojnów
  • 86 Gmina Pajęczno
  • 87 Gospodarka Odpadami - Pelplin
  • 89 Gmina Szczytna
  • 91 [TEST] Gmina Ustka
  • 95 [TEST] Gmina Moszczenica
  • 99 ZGPD-7
  • 100 Gmina Mysłakowice
  • 101 Gmina Krotoszyce
  • 103 Gmina Sobótka
  • 104 Gmina Wołów
  • 109 Gospodarka Odpadami - Starogard Gdański
  • 111 Gmina Inowrocław
  • 112 Gmina Dobra
  • 114 Gmina Słupno
  • 115 Gmina Mielec
  • 116 Gmina Bardo
  • 117 Gmina Żmigród
  • 118 [TEST] Gmina Wołów
  • 119 Gmina Stawiguda
  • 120 Gmina Starogard Gdański
  • 121 Gmina Nowa Ruda
  • 122 Gmina Legnickie Pole
  • 123 Gmina Brzeziny
  • 124 Gmina Zduńska Wola
  • 125 Gmina Międzybórz
  • 127 Gmina Osiecznica
  • 128 Gmina Słupca
  • 136 Gmina Grabów nad Prosną
  • 140 Gmina Mokrsko
  • 142 Strzelce Krajeńskie
  • 144 Gmina i Miasto Dzierzgoń
  • 145 Gmina Brzeg Dolny
  • 146 Gmina Wiązów
  • 149 Przedsiębiorstwo Gospodarki Komunalnej w Wołowie Sp. z o.o.
  • 150 Gmina Staszów
  • 153 Miasto Wałbrzych
  • 154 Miasto Rejowiec Fabryczny
  • 155 [TEST] Urząd Miejski Krzeszowice
  • 158 Gmina Grodzisk Mazowiecki
  • 159 Gmina Świecie
  • 160 Gmina Kozy
  • 161 Gmina Gniew
  • 162 Gmina Ostrowiec Świętokrzyski
  • 163 Gmina Skarszewy
  • 164 Gminne Przedsiębiorstwo Komunalne Sp. z o.o. w Skarszewach
  • 165 Gmina Porąbka
  • 166 Gmina Zbrosławice
  • 167 Gmina Szumowo
  • 168 KOMUS
  • 169 Miasto i Gmina Łasin
  • 170 Zakład Gospodarki Komunalnej Sp. z o.o.
  • 171 Gmina Kamionka Wielka
  • 172 Gmina Czernichów
  • 173 Gmina Świdnica
  • 174 Klient Szablonowy - Ekostrażnik
  • 175 Gmina Daleszyce
  • 176 [TEST] Gmina Szkolenie DU
  • 177 Gmina Nowy Staw
  • 178 Gmina Przeworno
  • 179 Gmina Pruszcz
  • 180 [TEST] Gmina Bisztynek
  • 181 Gmina Władysławowo
  • 182 Gmina Czechowice- Dziedzice
  • 183 ABRUKO PLUS
  • 184 Miasto i Gmina Morawica
  • 185 Gmina Wilkowice
  • 186 Gmina Wojcieszków
  • 187 Gmina Gorzyce
  • 188 Gmina Miedziana Góra
  • 189 Gmina Mogilany
  • 190 Gmina Gościno
  • 191 Gmina Ulan-Majorat
  • 192 Gmina Wąchock
  • 193 Gmina Wodzisław
  • 194 Miasto Malbork
  • 195 Gmina Grodków
  • 196 Gmina Zaleszany
  • 197 Gmina Gać
  • 198 Gmina Kluczbork
  • 199 Miasto Inowrocław
  • 200 Ekologiczny Związek Gmin Dorzecza Koprzywianki
  • 201 Gmina Miejska Kowal
  • 202 Gmina Kruszwica
  • 203 Gmina Przykładowa
  • 204 Gmina Radoszyce
  • 205 Gmina Osiek
  • 206 Gmina Pawłowice
  • 208 Gmina Gaworzyce
  • 209 Gmina Lubrza
  • 210 Parafia św. Wojciecha Biskupa i Męczennika w Nidzicy
  • 211 Gmina Pyskowice
  • 212 Gmina Nowa Słupia
  • 213 Stowarzyszenie Centrum Wspierania Organizacji Pozarządowych i Inicjatyw Obywatelskich
  • 214 Gmina Sośno
  • 215 Gmina Dygowo
  • 216 Gmina Bartniczka
  • 217 [TEST] Blisko
  • 218 Gmina Jeżewo
  • 219 Gmina Olsztynek
  • 220 Gmina Krzanowice
  • 221 Gmina Wierzchlas
  • 222 Gmina Miejska Hrubieszów
  • 223 Miasto Rydułtowy
  • 224 Gmina Gorlice
  • 225 Gmina Sztum
Found IDs using
import requests
import time

url = "https://gateway.sisms.pl/akun/api/owners/{id}/info"
for i in range(300):
    r = requests.get(url.format(id=i))
    if r.status_code != 200:
        # print(i, "not found")
        continue
    data = r.json()
    if "TIMETABLE" not in data["tabs"]:
        print(i, data.get("NAME", "no name"), "has no timetable")
        continue

    print(i, data["name"])
    time.sleep(.1)

@btaczala
Copy link
Author

Oh man that's awesome; thanks a lot for that. I'll adjust the PR later today.

@btaczala
Copy link
Author

@5ila5 Update PR; I've added a helper script https://github.com/btaczala/hacs_waste_collection_schedule/blob/blisko/custom_components/waste_collection_schedule/waste_collection_schedule/service/Blisko_searcher.py that can/must be used to figure out formattedID of the end query. Hope this is ok

@btaczala btaczala requested a review from 5ila5 November 14, 2024 21:35
@5ila5
Copy link
Collaborator

5ila5 commented Nov 15, 2024

I like your script, but we try to move away from these kinds of scripts as a lot of seem to not be able to run them properly, so I think integrating this functionality directly in the source is a better idea as it integrates better in the GUI configuration.

I still think hard-coding the region is the way to go:

Hardcoded regions and allow directly passing region, city, street, house_number arguments:
e.g.

    def __init__(
        self,
        regionId: str | int | None = None,
        formattedId: str | None = None,
        region: str | None = None,
        city: str | None = None,
        street: str | None = None,
        house_number: str | None = None,
    ):

and then some checks like

        if not regionId:
            if not region:
                raise SourceArgumentRequiredWithSuggestions(
                    argument="region",
                    message="Region or Region ID is required",
                    suggestions=[str(region["region_name"]) for region in REGIONS],
                )
            for region_item in REGIONS:
                if region.replace(" ", "") == region_item[
                    "region_name"
                ].lower().replace(" ", ""):
                    regionId = region["id"]
                    break

and calling your funtions from the script (maybe a bit modified to better fit this use case). you could put them into the service folder. verifing the arguments and setting the attribute regionId formattedId

I know it isn't quite as clean but we do not have a good way to show custom wizards to configure sources throug the GUI (and I don't have that much time to work on one atm.)

if args.region and args.city:
streets_json = all_street_per_city(args.region, args.city)
if streets_json:
print(streets_json)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing with print(json.dumps(streets_json, indent=2)) produces a way better readable result
(same in other printing functions)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ddb45dd

@piotrpot
Copy link

I think one piece is missing.
There are cities/towns that do not have streets, only building numbers. For example: --region 112 --city 32:11:01:2:0774173.

In such case, we should directly request town addresses: https://gateway.sisms.pl/akun/api/owners/112/townAddresses/list?townId=32:11:01:2:0774173

In result, we can use the formatted town address, like this: 32:11:01:2:0774173::1.

Other than that, great job! I tested it, and it works fine.

@btaczala
Copy link
Author

Done in bb49ada 😄

@5ila5
Copy link
Collaborator

5ila5 commented Nov 28, 2024

What about my comment above? Are you interested in implementing it that way? I'd still prefer this approach, but the current state is usable and making it more user-friendly could be done when there is a way to have real custom configuration forms in the GUI setup.

@btaczala

This comment was marked as off-topic.

@btaczala
Copy link
Author

@5ila5 yeah sure I can restructure that in a way that fits project needs. Will try to change it during the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants