socialwifi / RouterOS-api

Python API to RouterBoard devices produced by MikroTik.
MIT License
251 stars 100 forks source link

I don't know how to manipulate the answers #64

Closed Chkm64 closed 3 years ago

Chkm64 commented 3 years ago

I am using this example

list_address = api.get_resource('/queue/simple') indice = list_address.get() print(indice)

but the only thing I can do is see the data, I would like to convert it to arrays or variables

[{'id': '1', 'name': 'TEST', 'target': '10.1.1.0/24', 'parent': 'none', 'packet-marks': '', 'priority': '8/8', 'queue': 'default-small/default-small', 'limit-at': '0/0', 'max-limit': '5000000/40000000', 'burst-limit': '0/0', 'burst-threshold': '0/0', 'burst-time': '0s/0s', 'bucket-size': '0.1/0.1', 'bytes': '0/0', 'total-bytes': '0', 'packets': '0/0', 'total-packets': '0', 'dropped': '0/0', 'total-dropped': '0', 'rate': '0/0', 'total-rate': '0', 'packet-rate': '0/0', 'total-packet-rate': '0', 'queued-packets': '0/0', 'total-queued-packets': '0', 'queued-bytes': '0/0', 'total-queued-bytes': '0', 'invalid': 'false', 'dynamic': 'false', 'disabled': 'false', 'comment': 'TEST DESDE API QUEUE SIMPLE'}, {'id': '2', 'name': 'NewTest', 'target': '10.1.1.0/24', 'parent': 'none', 'packet-marks': '', 'priority': '8/8', 'queue': 'default-small/default-small', 'limit-at': '0/0', 'max-limit': '8000000/40000000', 'burst-limit': '0/0', 'burst-threshold': '0/0', 'burst-time': '0s/0s', 'bucket-size': '0.1/0.1', 'bytes': '0/0', 'total-bytes': '0', 'packets': '0/0', 'total-packets': '0', 'dropped': '0/0', 'total-dropped': '0', 'rate': '0/0', 'total-rate': '0', 'packet-rate': '0/0', 'total-packet-rate': '0', 'queued-packets': '0/0', 'total-queued-packets': '0', 'queued-bytes': '0/0', 'total-queued-bytes': '0', 'invalid': 'false', 'dynamic': 'false', 'disabled': 'false', 'comment': 'TEST DESDE API QUEUE SIMPLE'}]

please helpme

Chkm64 commented 3 years ago

Hello again I found what I was looking for to be able to access what I need I just needed to handle it as an array.

print (index [1] ['name'])

NewTest

Sorry but I am new to Python. I hope my problem helps someone.