sheatsb (owner)

Revisions

gist: 177805 Download_button fork
public
Public Clone URL: git://gist.github.com/177805.git
Embed All Files: show embed
Tweetie + Last.fm.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
 
# This script tweets "I'm listening to ..." via Tweetie
# It gets the information from http://last.fm
 
# This script is OS X only.
 
# This script is public domain
# Written by Jeena Paradies <spam@jeenaparadies.net> 2009-07-23
 
# Change the username to yours:
username = "jeenaparadies"
 
# Save the script somewhere, for example:
# ~/Library/Scripts/twlastfm.rb
#
# Make it executable on the console:
# chmod 755 ~/Library/Scripts/twlastfm.rb
#
# Use Quicksilver to start it.
 
require 'uri'
require 'net/http'
require "rexml/document"
 
url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=";
url += username;
url += "&api_key=213ac7a42cd7a69b82b7a57c6b067c6c";
 
xml_str = Net::HTTP.get_response(URI.parse(url)).body
doc = REXML::Document.new(xml_str)
track = doc.root.elements[1].elements[1].elements
 
song = track["name"].text
artist = track["artist"].text
album = track["album"].text
 
text = "I\'m listening to „#{song}“ by „#{artist}“"
text += " from the album „#{album}“" unless album.nil?
text += "."
 
system("open \"tweetie:#{text}\"")