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

Tilføj Københavns kommune #195

Open
MikOsle opened this issue Dec 8, 2024 · 2 comments
Open

Tilføj Københavns kommune #195

MikOsle opened this issue Dec 8, 2024 · 2 comments
Labels
feature request New feature or request

Comments

@MikOsle
Copy link

MikOsle commented Dec 8, 2024

Describe the feature you wish to make a request for

Er det mulig at tilføje Københavns kommune? De laver deres tømmekalender tilgængelig som iCal. https://nemaffaldsservice.kk.dk

Describe alternatives you've considered

No response

Additional context

No response

@MikOsle MikOsle added the feature request New feature or request label Dec 8, 2024
@briis
Copy link
Owner

briis commented Dec 9, 2024

De er på listen. Udfordringen var at finde et Kundenummer for en given adresse, men jeg er tæt på en løsning der.
Kan ikke sige hvornår det er løst - og ved ikke om jeg løber ind i andre udfordringer.
Men der arbejdes på det.

@MikOsle
Copy link
Author

MikOsle commented Jan 10, 2025

Jeg har noget lille kendskab til python og det at lave integration til HA, men det er lykkes mig at lave dette script i AppDaemon til at hent Kundenummer på en hvilken som helst address i KK. Måske det kan bruges.

import appdaemon.plugins.hass.hassapi as hass
import requests
from bs4 import BeautifulSoup

class CustomerIdLookup(hass.Hass):

    def initialize(self):
        # Listen for the custom event to trigger the customer ID lookup
        self.listen_event(self.handle_address_input, "customer_id_lookup_event")

    def handle_address_input(self, event_name, data, kwargs):
        # Extract the address from the event data
        address = data.get("address")
        if address:
            customer_id = self.get_customer_id(address)
            self.log(f"Customer ID for address '{address}': {customer_id}")
            
            # Fire a new event with the customer ID or error message as data
            if customer_id:
                # Fire the customer_id_result_event with the found customer ID
                self.fire_event("customer_id_result_event", customer_id=customer_id)
            else:
                # Fire the customer_id_result_event with an error message
                self.fire_event("customer_id_result_event", error_message=f"Customer ID not found for address: {address}")

    def get_customer_id(self, address):
        base_url = "https://nemaffaldsservice.kk.dk/WasteHome/SearchCustomerRelation"
        session = requests.Session()
        initial_page = session.get("https://nemaffaldsservice.kk.dk")
        soup = BeautifulSoup(initial_page.content, 'html.parser')
        token = soup.find('input', {'name': '__RequestVerificationToken'})['value']

        data = {
            '__RequestVerificationToken': token,
            'SearchTerm': address
        }

        response = session.post(base_url, data=data)

        soup = BeautifulSoup(response.content, 'html.parser')
        if response.history:
            redirect_url = response.history[-1].headers['Location']
            customer_id = redirect_url.split('customerId=')[1].split('&')[0]
            return customer_id
        else:
            return None

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

No branches or pull requests

2 participants