Archive for October 2nd, 2007

Autumn Leaves Leaf #2: Feeder

Blogging, Business, CLI, Linux, Random Thoughts, Ruby (on or off) Rails, Software Development | Posted by apokalyptik
Oct 02 2007

This handy little bot keeps track of RSS feeds, and announces in the channel when one is updated. (note: be sure to edit the path to the datafiles) Each poller runs inside its own ruby thread, and can be run on its own independent schedule

require 'thread'
require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'
require 'fileutils'
require 'digest/md5'
 
class Feeder < AutumnLeaf
 
def watch_feed(url, title, sleepfor=300)
  message "Watching (#{title}) [#{url}] every #{sleepfor} seconds"
  feedid = Digest::MD5.hexdigest(title)
  Thread.new {
    while true
      begin
        content = ""
        open(url) { |s|
          content = s.read
        }
        rss = RSS::Parser.parse(content, false)
        rss.items.each { |entry|
          digest = Digest::MD5.hexdigest(entry.title)
          if !File.exist?("/tmp/.rss.#{feedid}.#{digest}")
            FileUtils.touch("/tmp/.rss.#{feedid}.#{digest}")
            message "#{entry.title} (#{title}) #{entry.link}"
          end
          sleep(2)
        }
      rescue
        sleep(2)
      end
      sleep(sleepfor)
    end
  }
  sleep(1)
end
 
def did_start_up
  watch_feed("http://planet.wordpress.org/rss20.xml", "planet", 600)
  watch_feed("http://wordpress.com/feed/", "wpcom", 300)
end
 
end

Autumn Leaves Leaf #1: Announcer

Blogging, Business, CLI, Linux, Random Thoughts, Ruby (on or off) Rails, Software Development, Web Stuff | Posted by apokalyptik
Oct 02 2007

This bot is perfect for anything where you need to easily build IRC channel notifications into an existing process. It’s simple, clean, and agnostic. Quite simply you connect to a TCP port, give it one line, the port closes, the line given shows up in the channel. eg: echo ‘hello’ | nc -q 1 bothost 22122

require 'socket'
require 'thread'
 
class Announcer < AutumnLeaf
 
        def handle_incoming(sock)
                Thread.new {
                line = sock.gets
                message line
                sock.close
                }
        end
 
        def did_start_up
                Thread.new {
                        listener = TCPServer.new('',22122)
                        while (new_socket = listener.accept)
                                handle_incoming(new_socket)
                        end
                }
        end
 
end

Autumn Leaves (a ruby framework for IRC bots)

Business, CLI, Linux, Ruby (on or off) Rails, Software Development, Web Stuff | Posted by apokalyptik
Oct 02 2007

What an awesome awesome thing for people who use IRC in their day to day lives!  I’ll post a couple of utility leaves here real quick.

Link: http://www.shutupgeorge.com/al-docs/