[Python] How to Retrieve Data from Firebase using Python

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to Python and I would like to connect to Firebase using Python. I can successfully add and modify Firebase using put() and patch(), but I can't find a way to retrieve my data from Firebase.

    Code:

    import serial
    import time
    import requests
    import json

    firebase_url = 'https://testing1639.firebaseio.com'

    #Connect to Serial Port for communication
    ser = serial.Serial('/dev/ttyUSB0', 9600)

    #Setup a loop to send temperature values at fixed intervals in seconds
    fixed_interval = 2

    while 1:
    try:
    #Temperature value obtained from Arduino + LM35 Temp Sensor
    temperature_c = ser.readline()
    #Current time and date
    time_hhmmss = time.strftime('%H:%M:%S')
    date_mmddyyyy = time.strftime('%d/%m/%Y')

    #Current location name
    temperature_location = 'Mumbai-Kandivali' ;

    print temperature_c + ',' + time_hhmmss + ',' + date_mmddyyyy + ',' + temperature_location

    #Insert record
    data = {'date':date_mmddyyyy,'time':time_hhmmss,'value':temperature_c}

    result = requests.post(firebase_url + '/' + temperature_location + '/temperature.json', data=json.dumps(data))

    #Insert record
    print 'Record inserted. Result Code = ' + str(result.status_code) + ',' + result.text
    time.sleep(fixed_interval)

    except IOError:
    print('Error! Something went wrong.')
    time.sleep(fixed_interval)


    How can I modify it to retrieve the data?

    Continue reading...

Compartilhe esta Página