I am trying to extract virtualIP and onvifPort from a (.db) file.
I have a database.db file, which looks like this:
{
"devices": {
"193619374120978": {
"cameras": {
"14:a7:8b:08:e0:7c": {
"slots": {
"3": {
"onvifPort": "17005",
"rtspPort": "18005",
"virtualIP": "10.27.15.75",
"pubIP": "",
"pubOnvifPort": "0",
"pubRtspPort": "0"
}
}
},
"ac:cc:8e:a8:84:e1": {
"slots": {
"2": {
"onvifPort": "17003",
"rtspPort": "18003",
"virtualIP": "10.27.15.75",
"pubIP": "",
"pubOnvifPort": "0",
"pubRtspPort": "0"
}
}
},
"14:a7:8b:22:86:f6": {
"slots": {
"1": {
"onvifPort": "17004",
"rtspPort": "18004",
"virtualIP": "10.27.15.75",
"pubIP": "",
"pubOnvifPort": "0",
"pubRtspPort": "0"
}
}
}
}
}
}
}
I have to read this file using python and assign this values to python variables.
I am new to python and I just tried something like this, but I am not getting the desired output. I would like to know how to open and read a (.db) file and assign the values
with open("bmdatabase.db","r") as infile:
inputs = json.load(infile)
#con = sqlite3.connect('bmdatabase.db')
#c = con.cursor()
for item in range(len(inputs["devices[].cameras[].slots[]"])):
IP = inputs["devices[].cameras[].slots[]"][item]["virtualIP"]
PORT = inputs["devices[].cameras[].slots[]"][item]["onvifPort"]
expected output: username and password should be constant for all the 3 devices
IP = virtualIP of slot[1]from database.db file
PORT = onvifPort of slot[1] from database.db file
USERNAME = "admin"
PASSWORD = "Abcd"
IP = virtualIP of slot[2]from database.db file
PORT = onvifPort of slot[2] from database.db file
USERNAME = "admin"
PASSWORD = "Abcd"
IP = virtualIP of slot[3]from database.db file
PORT = onvifPort of slot[3] from database.db file
USERNAME = "admin"
PASSWORD = "Abcd"
can anyone help me with this??