Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Set Gajim's away message to your last tweet

This Ruby code fetches the latest tweet from the Twitter RSS feed and then uses it to update the autoaway message in Gajim.

   1  
   2  #!/usr/bin/ruby
   3  # file: RGajim-updater.rb
   4  
   5  require 'open-uri'
   6  require 'rexml/document'
   7  include REXML
   8  
   9  
  10  class GajimUpdater
  11  
  12    attr_accessor :url, :user
  13  
  14    def initialize_doc()
  15      @user = 'jrobertson'
  16      @url = 'http://twitter.com/statuses/user_timeline/763224.rss'
  17    end
  18  
  19    def write_config(msg)
  20      filepath = '/home/james/.gajim/'
  21      filein = File.new(filepath + 'config','r')
  22      buffer = filein.read
  23      filein.close
  24  
  25      am = 'autoaway_message = '
  26      new_buffer = buffer.gsub(/#{am}.*/,am + msg)
  27  
  28      fileout = File.new(filepath + 'config','w')
  29      fileout.puts new_buffer
  30      fileout.close
  31      puts 'config file updated!'
  32    end
  33  
  34    def get_latest_msg()
  35  
  36      puts 'getting the latest tweet ...' 
  37      buffer = open(@url,
  38           'User-Agent' => 'RGajim-updater').read
  39  
  40      doc = Document.new(buffer)
  41      doc.root.elements['//item/title'].text.to_s[/[^#{@user} :].*/]
  42    end
  43  end
  44  
  45  if __FILE__ == $0 then
  46  
  47    g = GajimUpdater.new()
  48    g.url = 'http://twitter.com/statuses/user_timeline/763224.rss'
  49    g.user = 'jrobertson'
  50    title = g.get_latest_msg()
  51    g.write_config(title)
  52  
  53  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS