Skip to content

Format JSON

daufinsyd edited this page Mar 8, 2017 · 7 revisions

Format des reponses json

Format

serveur:

{
"0":{"codeCmd":"0","cmd":"ls","params":["a","r"]},
"1":{"codeCmd":"1","cmd":1,"params":["param1","param2"]}
}

codeCmd:

 0: commande bash (seulement pour admin)
 1: fonction définie en python
 2: setMaxVol
  • On exécute d'abord les fonctions bash
  • Puis les fonctions définies (hors exctinction / reboot)
  • Enfin reboot / shutdown si demandé

Commandes prédéfinies

valeurs de cmd si codeCmd est égal à 1

 1: update
 2: upgrade
 3: distupgrade
 10: reboot

Utilisation

Nouvelle

rep = requests.post('http://127.0.0.1:8000/wthit/imbored', data=data)
rep.json()[i]  # i = index

Ancienne

import json
with open('test.json') as json_file:
    data=json.load(json_file)
data["0"]["codeCmd"]...
Clone this wiki locally