@@ -0,0 +1,1354 @@
+import hmac%0Aimport os%0Aimport unicodedata%0Afrom enum import Enum%0Afrom typing import Optional%0A%0Afrom sqlalchemy import func%0A%0Afrom pycroft.model.swdd import Tenancy%0A%0Aswdd_hmac_key = os.environ.get('SWDD_HASH_KEY')%0A%0A%0Aclass TenancyStatus(Enum):%0A    PROVISIONAL = 1%0A    ESTABLISHED = 2%0A%0A%0Adef get_swdd_person_id(first_name: str, last_name: str, birthdate: str) -%3E Optional%5Bint%5D:%0A    %22%22%22%0A    Builds a hmac hash from the given parameters and searches for a match in the Tenancy view%0A%0A    :param first_name: The first name%0A    :param last_name: The last name%0A    :param birth_date: Date in ISO-8601%0A    :return: The person_id if found, else None%0A    %22%22%22%0A%0A    if swdd_hmac_key is None:%0A        raise ValueError(%22No hmac key set%22)%0A%0A    digest_maker = hmac.new(swdd_hmac_key.encode(), digestmod=%22sha512%22)%0A%0A    norm_str = unicodedata.normalize(%22NFC%22, %22%7B%7D_%7B%7D_%7B%7D%22.format(first_name, last_name, birthdate)%0A                                                      .lower()).encode('utf-8')%0A%0A    digest_maker.update(norm_str)%0A%0A    person_hash = digest_maker.hexdigest().upper()%0A%0A    return Tenancy.q.filter_by(person_hash=person_hash, status_id=TenancyStatus.ESTABLISHED.value).first()%0A%0A%0Adef get_relevant_tenancies(person_id: int):%0A    return Tenancy.q.filter_by(person_id=person_id, status=TenancyStatus.ESTABLISHED.value)%5C%0A        .filter(Tenancy.mietende %3E func.now()).all()%0A

Add swdd lib