import requests
import json
import prettytable as pt

# URL de l'API
url = "http://192.168.1.49/getVictron"

# Faire la requete GET
response = requests.get(url)

# Verifier que la requete a reussi
if response.status_code == 200:
    # Charger le JSON recu
    data = response.json()
    
    # Creer un tableau PrettyTable
    table = pt.PrettyTable()
    table.field_names = ["ID", "Key Label", "Label", "Value"]
    
    # Ajouter les lignes au tableau
    for item in data:
        table.add_row([
            item.get("id", "N/A"), 
            item.get("key_label", "N/A"), 
            item.get("label", "N/A"), 
            item.get("value", "N/A")
        ])    
    # Afficher le tableau
    print(table)


