Advertisement
jevixlugya

Untitled

May 31st, 2023
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. class Homepage(Screen):
  2.     def __init__(self, **kwargs):
  3.         super().__init__(**kwargs)
  4.         self.t = None # used to hold thread    
  5.  
  6.     def on_enter(self,*args):
  7.         if self.t:  # only allow 1 thread to be created
  8.             return
  9.         self.t =threading.Thread(target=self.fetch_data)
  10.         self.t.start()
  11.  
  12.     def fetch_data(self):
  13.         time.sleep(1)
  14.         try:
  15.         #self.ids.screen_man.current = 'showdata'
  16.         # getting data from real-time database
  17.             self.firebase = firebase.FirebaseApplication('https://lexconnectionsapp-default-rtdb.firebaseio.com/', None)
  18.  
  19.             self.result = self.firebase.get('lexconnectionsapp-default-rtdb/products', None)
  20.             # data i fetched from my database
  21.             self.data = self.result
  22.             products = [item for item in self.data.values()]  # ignore primary key, get the inner dicts
  23.             for product in products:
  24.                 sc = ShowCard(**product)  # same as Showcard(description=product['description'],...)
  25.                 self.ids.prduct_grid.add_widget(sc)
  26.         except Exception as error:
  27.  
  28.             print (str(error))
  29.                
  30.        
  31.            # toast(str(error) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement