Last active
December 5, 2016 14:54
-
-
Save rsnorman/a5fb9898536940b9e882eec3a0e954fa to your computer and use it in GitHub Desktop.
Get Album Most Popular Track
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
highlighted_album = RecentHighlightedAlbum.find | |
# PopularAlbumTrack | |
highlighted_album = Album.find_by(name: 'Fall Be Kind') | |
artist = highlighted_album.artist | |
album = RSpotify::Artist.search(artist.name).first.albums.detect { |album| album.name == highlighted_album.name } | |
return unless album | |
top_track = album.tracks.sort(&:popularity).reverse.first | |
spotify_url = top_track.external_urls['spotify'] | |
artist_hashtag = "##{artist.name.gsub(/[^a-zA-Z]*/, '')}" | |
# AlbumTrackTweeter | |
tweet_text = ".@#{artist.twitter_screen_name}'s song \"#{top_track.name}\" is still great after #{highlighted_album.anniversary.count} years #{spotify_url} #{artist_hashtag} #indiemusic" | |
client = WistfulIndie::Twitter::Client.client | |
client.update(tweet_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment