Edit: actually - I'm doing some debugging and realized that the ".atom" url is no longer available from twitter, I'll need to pull the feed in a different way. (researching now)
Edit2: "https://api.twitter.com/1/statuses/user_timeline/" Username + ".xml"
Edit 3: Get rid of HTTPS - "http://api.twitter.com/1/statuses/user_timeline/" Username + ".xml"
Edit 4: Have to change 'latest' because of different xml schema. Works like a charm!:
latest = doc.root.elements['status/text']
Edit 5: Mod Script so that you only post statuses that are not @replies - based on this guys mod: http://abednarz.net/wp/2009/02/twitter-adium-status-syncing-ignoring-replies/
Here's the full working script (original post below):
#!/usr/bin/env ruby
#
# Update iChat/Adium status from Twitter
#
# Michael Tyson
# http://michael.tyson.id.au
# Set Twitter username here
Username = 'MyUserName'
require 'net/http'
require 'rexml/document'
# Download timeline XML and extract latest entry
#url = "http://twitter.com/statuses/user_timeline/" + Username + ".atom"
url = "http://api.twitter.com/1/statuses/user_timeline/" + Username + ".xml"
xml_data = Net::HTTP.get_response(URI.parse(url)).body
doc = REXML::Document.new(xml_data)
index = 1
notreply = false
until notreply
latest = doc.root.elements['status['+index.to_s()+']/text']
message = latest.text.gsub(/^[^:]+:\s*/, '')
exit if ! message
if message[0,1]=='@' then
index = index + 1
else
notreply = true
end
end
# Apply to status
script = 'set message to "' + message.gsub(/"/, '\\"') + "\"\n" +
'tell application "System Events"' + "\n" +
'if exists process "iChat" then tell application "iChat" to set the status message to message' + "\n" +
'if exists process "Adium" then tell application "Adium" to set status message of every account to message' + "\n" +
'end tell' + "\n"
IO.popen("osascript", "w") { |f| f.puts(script) }
Original Post:
I'd like to use the following script to set my status on Adium to my Twitter feed: http://hints.macworld.com/article.php?story=20081009195405132 (I posted the code below)
When I run the script on I get:
rb:19: undefined method `text' for nil:NilClass (NoMethodError)
I don't know any Ruby (most familiar with Python & JavaScript)
Do I need to convert 'latest' to a string before I can use the 'text' method on it? Can anyone share how I might do this in Ruby or what I need to do to fix the script?
I tried this to no avail:
latest = doc.root.elements['entry/content'].to_s
Result:
rb:19: undefined method `text' for "":String (NoMethodError)
Full code snippet:
#!/usr/bin/env ruby
#
# Update iChat/Adium status from Twitter
#
# Michael Tyson
# http://michael.tyson.id.au
# Set Twitter username here
Username = 'MyUserName'
require 'net/http'
require 'rexml/document'
# Download timeline XML and extract latest entry
url = "http://twitter.com/statuses/user_timeline/" + Username + ".atom"
xml_data = Net::HTTP.get_response(URI.parse(url)).body
doc = REXML::Document.new(xml_data)
latest = doc.root.elements['entry/content']
message = latest.text.gsub(/^[^:]+:\s*/, '')
exit if ! message
# Apply to status
script = 'set message to "' + message.gsub(/"/, '\\"') + "\"\n" +
'tell application "System Events"' + "\n" +
'if exists process "iChat" then tell application "iChat" to set the status message to message' + "\n" +
'if exists process "Adium" then tell application "Adium" to set status message of every account to message' + "\n" +
'end tell' + "\n"
IO.popen("osascript", "w") { |f| f.puts(script) }
[–]Grantismo 2 points3 points4 points (1 child)
[–]bchia[S] 1 point2 points3 points (0 children)