-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetDevicesCredentials.py
48 lines (38 loc) · 1.18 KB
/
GetDevicesCredentials.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import loginthingsboard as lt
import mgassets
import mgcustomers
import mgdevices
import time
import json
import os
_TBURL = "https://esc.isi.gr/"
_TBUSER = "[email protected]"
_TBPWD = "****************"
def updatedeviced(devices):
token = lt.gettoken(_TBURL,_TBUSER,_TBPWD)
for device in devices:
time.sleep(2)
data = mgdevices.getdevicecredentialsbytoken(
_TBURL,
device['id']['id'],
token)
while data is False:
time.sleep(5)
token = lt.gettoken(_TBURL,_TBUSER,_TBPWD)
data = mgdevices.getdevicecredentialsbytoken(
_TBURL,
device['id']['id'],
token)
if data != {}:
device['credentials'] = data
print(data)
with open('./output/devices_credentials.json', 'w', encoding='utf-8') as f:
json.dump(devices, f, ensure_ascii=False, indent=4)
def getgredentials():
with open('./output/devices.json', 'r', encoding='utf-8') as f:
devices = json.load(f)
#print(devices)
updatedeviced(devices)
if __name__ == '__main__':
getgredentials()