Brooks Nelson
Brooks Nelson

Reputation: 41

Working with a dataset on firebase sending via python

I was testing a dataset I have on Firebase.

Firebase Snapshot Using the this instruction

 result = firebase.get('/Lot',"I") #THIS PULLS THE DATASET FROM FIREBASE

When I use the the firebase.get instruction in python I get the following.

runfile('C:/Users/Maint.Tech/parking_app/firebase_test.py', 
wdir='C:/Users/Maint.Tech/parking_app')
[None, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 
0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 
1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 
0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 
1, 0, 1, 1, 1, 0]
  1. What is "None"? When I manipulate the numbers after "none" everything reflects in dataset correctly.
  2. From python I am trying to take a array in python and send this via json list. How would I set up python array to reflect the correct structure to send to firebase? This is the instruction I have sent that updates the dataset correctly. Just need to figure out how to write the python right..

send_data = firebase.put('/Lot','I',[None, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0])

Thank you.

Upvotes: 0

Views: 99

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599571

Firebase doesn't natively store arrays. When you send it an array, it stores the items from that array in number properties instead.

So if you store the follow array in JavaScript:

ref.set([ first, second, third ]);

Firebase actually stores it as:

{
  "0": "first",
  "1": "second",
  "2": "third"
}

Now if you remove the first item from the database, and read the result back into an array in JavaScript, you get:

[ undefined, "second", "third" ]

And that last one seems very close to what you have in your Python script.

But in this case that's all just background information. It looks like you're actually sending the None yourself in the put to Firebase. If you don't want None in there, don't send it, and instead do:

send_data = firebase.put('/Lot','I',[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0])

Upvotes: 1

Related Questions