Created
May 17, 2011 23:59
-
-
Save statianzo/977704 to your computer and use it in GitHub Desktop.
Scrobbles your latest last.fm song to twitter
This file contains 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
require 'open-uri' | |
require 'xmlsimple' | |
require 'yaml' | |
config = YAML::load(File.open('musicmonday.yaml')) | |
lastfm_username = config['settings']['lastfm']['username'] | |
lastfm_api = config['settings']['lastfm']['api'] | |
recent_tracks_url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=#{lastfm_username}&api_key=#{lastfm_api}&limit=1" | |
twitter_url = "http://twitter.com/statuses/update.xml" | |
twitter_username = config['settings']['twitter']['username'] | |
twitter_password = config['settings']['twitter']['password'] | |
open recent_tracks_url do |body| | |
data = XmlSimple.xml_in body.read | |
recenttracks = data['recenttracks'][0] | |
track = recenttracks['track'][0] | |
@artist = track['artist'][0]['content'] | |
@name = track['name'][0] | |
end | |
text = URI.escape "If today were Monday, I'd tag it. \"#{@name}\" by #{@artist} #lastfm (musicmonday.rb test)" | |
result = %x[curl -s -S -u #{twitter_username}:#{twitter_password} -d status="#{text}" #{twitter_url}] |
This file contains 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
settings: | |
lastfm: | |
username: | |
api: | |
twitter: | |
username: | |
password: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment