def add_group(self, email, select_channel_ids, group_names): youtube_related = Youtube() logging.info('[Action] %s add %s channels into %s' % (email, len(select_channel_ids), group_names)) for select_channel_id in select_channel_ids: for group_name in group_names.split(','): ## Add the group name into UserChannel collection search_user_channel_result = UserChannel.query( UserChannel.email == email, UserChannel.channel_id == select_channel_id).get() if search_user_channel_result.group_name == None: search_user_channel_result.group_name = [group_name] search_user_channel_result.put() else: if group_name not in search_user_channel_result.group_name: search_user_channel_result.group_name.append( group_name) ## Update the new group name search_user_channel_result.put() ## Add the group name into Channel collection search_channel_result = Channel.query( Channel.channel_id == select_channel_id).get() channel_details = youtube_related.get_channel_details( channel_id=select_channel_id, email=email) upload_playlist_id = channel_details['items'][0][ 'contentDetails']['relatedPlaylists']['uploads'] ## If there is no group for the channel, then add. If there is group, then append if search_channel_result.groups == None: search_channel_result.groups = [group_name] search_channel_result.upload_playlist_id = upload_playlist_id search_channel_result.put() ## Get the latest uploaded video self.parse_latest_videos(select_channel_id) elif group_name not in search_channel_result.groups: search_channel_result.groups.append(group_name) search_channel_result.upload_playlist_id = upload_playlist_id search_channel_result.put() logging.info('[Success] %s add %s channels into %s' % (email, len(select_channel_ids), group_names))
def add_group(self, email, select_channel_ids, group_names): youtube_related = Youtube() logging.info('[Action] %s add %s channels into %s' % (email, len(select_channel_ids), group_names)) for select_channel_id in select_channel_ids: for group_name in group_names.split(','): ## Add the group name into UserChannel collection search_user_channel_result = UserChannel.query(UserChannel.email == email, UserChannel.channel_id == select_channel_id).get() if search_user_channel_result.group_name == None: search_user_channel_result.group_name = [group_name] search_user_channel_result.put() else: if group_name not in search_user_channel_result.group_name: search_user_channel_result.group_name.append(group_name) ## Update the new group name search_user_channel_result.put() ## Add the group name into Channel collection search_channel_result = Channel.query(Channel.channel_id == select_channel_id).get() channel_details = youtube_related.get_channel_details(channel_id=select_channel_id, email=email) upload_playlist_id = channel_details['items'][0]['contentDetails']['relatedPlaylists']['uploads'] ## If there is no group for the channel, then add. If there is group, then append if search_channel_result.groups == None: search_channel_result.groups = [group_name] search_channel_result.upload_playlist_id = upload_playlist_id search_channel_result.put() ## Get the latest uploaded video self.parse_latest_videos(select_channel_id) elif group_name not in search_channel_result.groups: search_channel_result.groups.append(group_name) search_channel_result.upload_playlist_id = upload_playlist_id search_channel_result.put() logging.info('[Success] %s add %s channels into %s' % (email, len(select_channel_ids), group_names))