#!/usr/bin/env ruby require "db" require "simple-rss" require "open-uri" $MIN_CONTENT = 10 while (true) categories = Category.find(:all) threads = [] for category in categories threads << Thread.new(category) { |c| contents = Content.find(:all, :conditions => ['category_id = ?', c.id]) if contents.count < $MIN_CONTENT needed = $MIN_CONTENT - contents.count feeds = Feed.find(:all, :conditions => ['category_id = ?', c.id]) feeds.each { |feed| begin rss = SimpleRSS.parse open(feed.url) feed.lastused_at = Time.now feed.save for item in feed.items end rescue end } end } end threads.each { |t| t.join } sleep(600) end