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