using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sony.Filtr.Core.EditorialPlaylists; using Sony.Filtr.Utility.Extensions; namespace Sony.Filtr.Worker.Onetime { public class RemovePlaylistsForUsers { private readonly EditorialPlaylistManager _editorialPlaylistManager; public RemovePlaylistsForUsers(EditorialPlaylistManager editorialPlaylistManager) { _editorialPlaylistManager = editorialPlaylistManager; } public async Task ExecuteTaskAsync() { var allPlaylists = await _editorialPlaylistManager.GetEditorialPlaylistsAsync(null, onlySony: false, onlyActive: false, lightWeight: true); List usernames = new List() { "glennpmcdonald", "thesoundsofspotify", "bestthingsonearth", "rockifyapp", "jazzifyapp", "bluesifyapp", }; var playlistsForUsers = allPlaylists.Where(p => usernames.Contains(p.SpotifyLink.ExtractSpotifyPlaylistUserName())).ToList(); var numPlaylists = playlistsForUsers.Count; Console.WriteLine($"Will remove {numPlaylists} playlists."); await playlistsForUsers.ItemIndex().ForEachAsync(5, async playlist => { Console.WriteLine($"Removing {playlist.Index} of {numPlaylists}. {playlist.Item.Name} for {playlist.Item.SpotifyLink.ExtractSpotifyPlaylistUserName()}"); await _editorialPlaylistManager.DeleteEditorialPlaylistAsync(playlist.Item); }); Console.WriteLine("All done"); Console.ReadLine(); } } }