All pastes #167348 Raw Edit

Stuff

public ruby v1 · immutable
·published 2006-09-11 22:01 UTC
rendered paste body
#!/usr/bin/env rubyrequire "db"require "simple-rss"require "open-uri"require "classifier"require "madeleine"MIN_CONTENT = 10while (true)  m = SnapshotMadeleine.new("bayes_data")  bayes = m.system  categories = Category.find(:all)  threads = []  for category in categories    threads << Thread.new(category) { |c|      contents = Content.find_by_category_id(:all, c.id)      if contents.nil? or contents.count < MIN_CONTENT        needed = MIN_CONTENT - contents.count        feeds = Feed.find_by_category_id(:all, c.id)        catch :no_feeds do          throw :no_feeds unless feeds          feeds.each { |feed|            begin              rss = SimpleRSS.parse open(feed.url)              feed.lastused_at = Time.now              feed.save              for item in feed.items                item_category = bayes.classify item.description                if item_category == c.name                  content = Content.new                  content.title = item.title                  content.link = item.link                  content.description = item.description                  content.category = c                  content.save                  needed = needed - 1                end                break unless needed > 0              end            rescue               print "b00m!"            end            break unless needed > 0          }        end      end    }  end  threads.each { |t| t.join }  sleep(600)end