def create_group_if_not_exists(self): current_user_id = SplitwiseApiUtils.splitwise_obj.getCurrentUser().id group_from_redis = self.client.get(f"sw-${current_user_id}") if not group_from_redis: group = Group() group.setName("Auto-Splitwise") friend_obj = self.get_friend( SplitwiseApiUtils.splitwise_obj.getFriends()) friend1 = User() friend1.setId(friend_obj.id) current_user_id = SplitwiseApiUtils.splitwise_obj.getCurrentUser( ).id user1 = User() user1.setId(current_user_id) users = [user1, friend1] group.setMembers(users) group_created = SplitwiseApiUtils.splitwise_obj.createGroup(group) group_id = group_created.id self.store_group_id_for_user(group_id, current_user_id)
def createGroup(info,groupName): # info contains, list of lists which have name and email sObj = Splitwise(consumer_key, secret_key) sObj.setAccessToken(session['access_token']) group = Group() group.setName(groupName) users = [] for data in info: newUser = createUser(data[0], data[1], data[2]) users.append(newUser) group.setMembers(users) sObj.createGroup(group)