def update_slouch_data(self, email: str): # update times slouched list if not self.data: # SET initial data value for user self.data = {'timesSlouched': [ {'date': "2019-09-09", 'numSlouch': 7}, {'date': "2019-09-10", 'numSlouch': 13}, {'date': "2019-09-11", 'numSlouch': 15}, {'date': "2019-09-12", 'numSlouch': 10}, {'date': "2019-09-13", 'numSlouch': 7}, {'date': "2019-09-14", 'numSlouch': 11}, {'date': "2019-09-15", 'numSlouch': 0} ]} self.data['timesSlouched'][6]['numSlouch'] += 1 # self.add_to_firebase() else: #UPDATE data value if self.data['timesSlouched'][6]['date'] != Utils.get_date(): #add new day to list for i in range(0, 5): self.data[i] = self.data[i + 1] self.data['timesSlouched'][6] = {'date': Utils.get_date(), 'numSlouch': 1} else: self.data['timesSlouched'][6]['numSlouch'] += 1 # self.add_to_firebase() self.save_to_firebase()
def __init__( self, email: str, password: str, data: Dict = { 'timesSlouched': [{ 'date': Utils.get_date(), 'numSlouch': 0 }, { 'date': Utils.get_date(), 'numSlouch': 0 }, { 'date': Utils.get_date(), 'numSlouch': 0 }, { 'date': Utils.get_date(), 'numSlouch': 0 }, { 'date': Utils.get_date(), 'numSlouch': 0 }, { 'date': Utils.get_date(), 'numSlouch': 0 }, { 'date': Utils.get_date(), 'numSlouch': 0 }] }): self.collection = 'users' self.email = email self.password = password self.data = data
def update_slouch_data(self, email: str): # update times slouched list user = self.find_by_email(email) if not user: # SET initial data value for user self.data[6]['numSlouch'] = self.data[6][ 'numSlouch'] = self.data[6]['numSlouch'] + 1 self.add_to_firebase() else: #UPDATE data value data = user.data if data[6]['numSlouch'] != Utils.get_date(): #add new day to list for i in range(0, 5): self.data[i] = self.data[i + 1] data[6] = {'date': Utils.get_date(), 'numSlouch': 1} else: data[6]['numSlouch'] = data[6]['numSlouch'] + 1 self.save_to_firebase()