I am trying to take sensor data from online api to a csv file using csv library. Whenever I am trying that i am getting multiple values appended in a single row that is increasing so on...
['22.00'] ['71.00'] ['0.00']
['22.00', '22.00'] ['71.00', '71.00'] ['0.00', '0.00']
['22.00', '22.00','22.00'] ['71.00', '71.00','71.00'] ['0.00','0.00', '0.00']
this is the output i get. Here is my code:
while True:
data_temp = requests.get(temp_url).json()
data_hum = requests.get(hum_url).json()
data_flame = requests.get(flame_url).json()
feilds_temp = data_temp['feeds']
feilds_hum = data_hum['feeds']
feilds_flame = data_flame['feeds']
with open('testdata.csv','a') as csv_file:
for x in feilds_temp:
temp.append(x['field1'])
for y in feilds_hum:
humid.append(y['field2'])
for z in feilds_flame:
flame.append(z['field3'])
csv_write = csv.DictWriter(csv_file, fieldnames= fieldnames)
data = {
"temperature": temp,
"humidity": humid,
"flame": flame
}
csv_write.writerow(data)
print(temp, humid, flame)
time.sleep(15)