use Purple; use HTTP::Request; use LWP::UserAgent; use XML::XPath; use XML::XPath::XMLParser; %PLUGIN_INFO = ( perl_api_version => 2, name => "Twitter Status Feed", version => "0.1", summary => "Use a Twitter feed as your status message.", description => "Use a Twitter feed as your status message.", author => "Aaron D. Santos aaronds109\@gmail.com", url => "http://pidgin.im", load => "plugin_load", unload => "plugin_unload", prefs_info => "prefs_info_cb" ); sub timeout_cb { my $plugin = shift; my @accounts = Purple::Accounts::get_all_active(); if (@accounts) { print "got accounts\n"; } else { print "get_all_active fail.\n"; } my $twitterusername = Purple::Prefs::get_string("/plugins/core/gtk-aaron_ds-twitterstatus/twitterusername"); my $twitterurl = "http://twitter.com/statuses/user_timeline/".$twitterusername.".xml?count=1"; my $ua = LWP::UserAgent->new; $ua->agent("pidgin-twitterstatusfeed/1.0"); $ua->max_size([1000000]); my $response = $ua->get($twitterurl); my $xml = XML::XPath->new(xml=>$response->content); my $status_message = $xml->findvalue('/statuses/status/text')->value(); my $saved_status = Purple::SavedStatus::get_current(); my $prev_status = $saved_status->get_message(); if($prev_status ne $status_message){ Purple::Debug::info("Twitter Status Feed", "Updating status message with ".$status_message." From ".$twitterurl."\n"); $saved_status->set_message($status_message); $saved_status->activate(); } # Reschedule timeout Purple::timeout_add($plugin, 10, \&timeout_cb, $plugin); } sub plugin_init { return %PLUGIN_INFO; } sub plugin_load { my $plugin = shift; Purple::Debug::info("gtk-aaron_ds-twitterstatus", "plugin_load() - Twitter Status Feed.\n"); # Here we are adding a set of preferences # The second argument is the default value for the preference. Purple::Prefs::add_none("/plugins/core/gtk-aaron_ds-twitterstatus"); Purple::Prefs::add_string("/plugins/core/gtk-aaron_ds-twitterstatus/twitterusername", ""); # Schedule a timeout for ten seconds from now Purple::timeout_add($plugin, 1, \&timeout_cb, $plugin); } sub plugin_unload { my $plugin = shift; Purple::Debug::info("gtk-aaron_ds-twitterstatus", "plugin_unload() - Twitter Status Feed.\n"); } sub prefs_info_cb { # The first step is to initialize the Purple::Pref::Frame that will be returned $frame = Purple::PluginPref::Frame->new(); # Create a new boolean option with a label "Boolean Label" and then add # it to the frame $ppref = Purple::PluginPref->new_with_label("Twitter Account Information"); $frame->add($ppref); # Create a text box. The default value will be "Foobar" as set by # plugin_load $ppref = Purple::PluginPref->new_with_name_and_label( "/plugins/core/gtk-aaron_ds-twitterstatus/twitterusername", "Twitter User Name"); $ppref->set_type(2); $ppref->set_max_length(120); $frame->add($ppref); return $frame; }