I have the following json:
{"sensors":
{"-KqYN_VeXCh8CZQFRusI":
{"bathroom_temp": 16,
"date": "02/08/2017",
"fridge_level": 8,
"kitchen_temp": 18,
"living_temp": 17,
"power_bathroom": 0,
"power_bathroom_value": 0,
"power_kit_0": 0
},
"-KqYPPffaTpft7B72Ow9":
{"bathroom_temp": 20,
"date": "02/08/2017",
"fridge_level": 19,
"kitchen_temp": 14,
"living_temp": 20,
"power_bathroom": 0,
"power_bathroom_value": 0
},
"-KqYPUld3AOve8hnpnOy":
{"bathroom_temp": 23,
"date": "02/08/2017",
"fridge_level": 40,
"kitchen_temp": 11,
"living_temp": 10,
"power_bathroom": 1,
"power_bathroom_value": 81,
}
}
}
This is the python code that I have so far:
from flask import Flask, render_template, json, url_for
from firebase import firebase
import os
firebase = firebase.FirebaseApplication('https://my-firebase-db-958b1.firebaseio.com/', None)
result = firebase.get('/Dublin-Ireland', None)
print "\n Json file created!\n"
data_temp = result.values()[0]
for key, value in data_temp.iteritems():
print key
print value
print "\n\n"
With the current code, I'm able to view the keys "KqYN_VeXCh8CZQFRusI", "KqYPPffaTpft7B72Ow9", etc.. and the values for those keys which are:
{"bathroom_temp": 16,
"date": "02/08/2017",
"fridge_level": 8,
"kitchen_temp": 18,
"living_temp": 17,
"power_bathroom": 0,
"power_bathroom_value": 0,
"power_kit_0": 0
},
and
{"bathroom_temp": 20,
"date": "02/08/2017",
"fridge_level": 19,
"kitchen_temp": 14,
"living_temp": 20,
"power_bathroom": 0,
"power_bathroom_value": 0
},
I need to get the secondlevel keys and their values. I'm trying to have a file for each key ("bathroom_temp", "power_bathroom", etc...) and save all the corresponding values of those keys in the file.
For example, the file "bathroom_temp.txt" will have the values "16, 20, 23".