Added debugging and error handling

This commit is contained in:
Yannis 2023-11-13 15:05:38 +01:00
parent a601a6f73a
commit 07e0193db5
2 changed files with 13 additions and 5 deletions

View file

@ -85,12 +85,18 @@ class Alcasar:
def update_statut(self): def update_statut(self):
"""Update the connexion statut""" """Update the connexion statut"""
data = self.ses.get("http://alcasar-0320002d.smile-education.fr:3990/json/status?callback=chilliJSON.reply") try:
statut = json.loads( data = self.ses.get("http://alcasar-0320002d.smile-education.fr:3990/json/status?callback=chilliJSON.reply")
data.text[17:-1]) statut = json.loads(
data.text[17:-1])
except requests.exceptions.RequestException:
self.connection_statut = False
return False, ""
self.connection_statut = statut["clientState"] # Update statuts variables with new data
self.connection_statut = bool(statut["clientState"])
self.logout_url = statut["redir"]["logoutURL"] self.logout_url = statut["redir"]["logoutURL"]
return self.connection_statut, self.logout_url
def disconnect(self): def disconnect(self):
"""Disconnect the user from the authentication service""" """Disconnect the user from the authentication service"""

View file

@ -6,7 +6,7 @@ if __name__ == '__main__':
print("Checking if the computer is connected on an Alcasar WI-FI...") print("Checking if the computer is connected on an Alcasar WI-FI...")
if alcasar.detect(): if alcasar.detect():
print("Alcasar Detected! Connecting...") print("Alcasar Detected! Connecting...")
result = alcasar.connect("BENDJEY", "Q8CSKR") result = alcasar.connect("USERNAME", "PASSWORD")
# Check result # Check result
match result: match result:
@ -23,3 +23,5 @@ if __name__ == '__main__':
input("disconnect ?") input("disconnect ?")
alcasar.disconnect() alcasar.disconnect()
else:
print("Not detected")