Firebase Admin - How to create new child dynamically

Project Information
Hi, I am creating a discord bot using python for a gaming community. The main purpose is to fetch information from users messages and store them under suitable nodes, which will then be queried by someone else for their reference.

Database Tree

Just like you can see that each yearNode will have monthNode and each monthNode will have dayNode.


d =
year = d.strftime("%Y")
month = d.strftime("%B")
day = d.strftime("%d")
ref = db.reference("/flights/{}/{}/{}".format(year, month, day))
data = ref.get()
l = []
state = False
while not(state):
    for i in data.keys():
      state = True
    newRef = db.reference("flights")
    g = newRef.get()

Modules used

  • date from datetime module
  • db from firebase-admin

Problem Identification
The main problem is that this code works when I manually create the database tree format. But when I am supposed to execute the program the next day, it doesn’t work. I have made few changes in lines 9 - 18, where I tried to create a while loop where the loop checks if there is a dayNode, if not create a dayNode in the except conditional. Good thing is the new dayNode actually gets created by the later part of the code in the program, doesn’t gets executed. Therefore, I guess there is a problem with the try except conditional due to which the program enters into a for loop, which doesn’t let the later part of the code unseen.