· 6 years ago · Nov 12, 2019, 10:42 PM
1from firebase import firebase
2
3import json
4import csv
5
6#Connect to the API
7firebase = firebase.FirebaseApplication('https://tigum-iot.firebaseio.com', None)
8
9n=0
10i=0
11
12#Variables to get
13temp = 'Temperature'
14air = 'Airflow'
15emg = 'EMG'
16time = 'Timestamp'
17
18#Retrieve the datas from API database
19result = firebase.get('/ArduinoData/', '')
20#Make the datas readable as json format
21array = json.dumps(result)
22#Define the retrieved datas as json format
23jsonToPython = json.loads(array)
24
25with open("yoclesdonnes.csv", "w") as csvfile:
26 f = csv.DictWriter(csvfile,fieldnames = ["Airflow", "EMG", "Temperature", "Timestamp"])
27 f.writeheader()
28
29 f = csv.writer(csvfile, delimiter=',')
30 #f.writerow(["Airflow", "EMG", "Temperature", "Timestamp"])
31
32 #Writing the csv file associated to the datas
33 for key in jsonToPython:
34 f.writerow([jsonToPython[key][air],
35 jsonToPython[key][emg],
36 jsonToPython[key][temp],
37 jsonToPython[key][time]])
38 n=n+1
39
40print(n)
41
42#Stocking json datas into an array
43#while(i<n):
44# print(jsonToPython[key][time])
45# i=i+1