Python - Create dynamic variable for firebase

Asked

Viewed 66 times

0

I have a code that you receive from a spreadsheet CodProduto, Descrição and Quantidade and then inserts them into the database. Only it does this 1000x looping.

How can I create variables with this db.child and do everything at once or in a smaller amount of times?

Code:

while contador2 < npedido2.count():

  while logica1 == logica2:

  db.child("Pedidos").child(str(npedido2[contador2])).child("CodProduto").update({contador2:
codpedido[contador2]})

  db.child("Pedidos").child(str(npedido2[contador2])).child("Descrição").update({contador2: descricao[contador2]})

  db.child("Pedidos").child(str(npedido2[contador2])).child("Quantidade").update({contador2: str(quantidade[contador2])})

  contador2 = contador2 + + 1
  • It will make it easier for someone to answer you if the above code is ideated correctly. Try using triple inverted apostrophe instead of forward (``` ) to demarcate the code snippet. Remember that in Python identation is not an "aesthetic accessory", but rather, defines the structure of your program.

2 answers

0

@Giovane,

If the library you are using is firebase. Use something like below:

from firebase import firebase


firebase = firebase.FirebaseApplication('URL of Database', None)
data =  { 'Name': 'John Doe',
          'RollNo': 3,
          'Percentage': 70.02
          }
result = firebase.post('/python-example-f6d0b/Students/',data)
print(result)

Withdrawn from here

In your case, construct the variable data with the CodProduto, Descrição and Quantidade.

You’d also have to hit the URL of Database and the url of post

I hope I’ve helped.

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.