using MoreLinq; using Sony.Filtr.Core.EditorialPlaylists; using System.IO; using System.Linq; using System.Threading.Tasks; namespace Sony.Filtr.Worker.Onetime { public class ExportPlaylistForCategorizedAsArtists { private readonly EditorialPlaylistManager _editorialPlaylistManager; public ExportPlaylistForCategorizedAsArtists(EditorialPlaylistManager editorialPlaylistManager) { this._editorialPlaylistManager = editorialPlaylistManager; } public async Task ExecuteAsync() { var editorialPlaylist = await _editorialPlaylistManager.GetEditorialPlaylistsAsync(null, onlySony: false, onlyActive: false, lightWeight: true); var playlists = editorialPlaylist.Where(p => p.PriorityLevel == 2).DistinctBy(p=> p.SpotifyLink); var playlistsWithAttributes = await _editorialPlaylistManager.GetPlaylistAttributesAsync(playlists); using (FileStream playlistExportFile = File.Open("PlaylistExport.csv", FileMode.OpenOrCreate)) { using (StreamWriter fileWriter = new StreamWriter(playlistExportFile)) { foreach (var extendedEditorialPlaylist in playlistsWithAttributes) { var csvRow = extendedEditorialPlaylist.EditorialPlaylist.SpotifyLinkUri + ";" + extendedEditorialPlaylist.EditorialPlaylist.Name.Replace(";", string.Empty) + ";" + extendedEditorialPlaylist.Attributes.Followers; await fileWriter.WriteLineAsync(csvRow); } } } } } }