#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import threading
import time
import requests


def task_active_sonde():
    while True:
        print(f"[INFO] – Get data activ radiosonde")

        url = "http://api.wettersonde.net/v1/telemetrie.php?option=1"  # Beispiel-API
        response = requests.get(url)

        # Prüfe den HTTP-Statuscode
        if response.status_code == 200:
            data = response.json()  # JSON-Antwort in Python-Dict umwandeln
            print(data)
            print("✅ Erfolgreiche API-Antwort:")
            print(f"Serial: {data['serial']}")
        else:
            print(f"❌ Fehler: HTTP {response.status_code}") 

        time.sleep(1)

def task2():
    while True:
        print(f"Thread 2 – Schritt")
        time.sleep(10)

# Zwei Threads erzeugen
t1 = threading.Thread(target=task_active_sonde)
t2 = threading.Thread(target=task2)

# Threads starten
t1.start()
t2.start()

# Warten, bis beide fertig sind
t1.join()
t2.join()

print("Beide Threads sind fertig!")
