import paramiko import psutil import json import time # --- CONFIG --- HOST = "147.79.103.165" PORT = 65002 USER = "u656531579" PASSWORD = "PRIES+j0" REMOTE_PATH = "domains/sys.hubworld.net/public_html/data.json" # chemin corrigé def get_battery_info(): battery = psutil.sensors_battery() if battery is None: return None, None level = round(battery.percent, 1) charging = "1" if battery.power_plugged else "0" return level, charging def update_remote_battery(): try: # Connexion SSH ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(HOST, port=PORT, username=USER, password=PASSWORD) sftp = ssh.open_sftp() # Télécharger le fichier with sftp.open(REMOTE_PATH, "r") as f: data = json.load(f) # Mettre à jour la batterie et l'état de charge level, charging = get_battery_info() if level is not None: data["battery"] = str(level) data["charge"] = charging print(f"[OK] Batterie {level}% | Charge: {charging}") else: print("[!] Impossible de lire la batterie") # Réécrire le fichier with sftp.open(REMOTE_PATH, "w") as f: f.write(json.dumps(data, indent=2)) sftp.close() ssh.close() except Exception as e: print(f"[ERREUR] {e}") if __name__ == "__main__": while True: update_remote_battery() time.sleep(3) # attend 1 minute