Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 7930ee856da79ed853d482049a79a93fa10c9cef @rizwanreza committed Jan 11, 2010
Showing with 502 additions and 0 deletions.
  1. 0 README
  2. +6 −0 lib/rosy.rb
  3. +35 −0 lib/rosy/parse.rb
  4. +16 −0 lib/rosy/record.rb
  5. +150 −0 spec/feeds/maxvoltar.rss
  6. +259 −0 spec/feeds/rubyinside.rss
  7. +23 −0 spec/rosy/parse_spec.rb
  8. +13 −0 spec/spec_helper.rb
0 README
No changes.
@@ -0,0 +1,6 @@
+$LOAD_PATH.unshift(File.dirname(__FILE__)) unless $LOAD_PATH.include?(File.dirname(__FILE__))
+
+require 'rosy/parse.rb'
+
+# rosy = Rosy::Parse.get_updates("http://feeds.feedburner.com/rizwanreza", "Jan 1 2009", "Jan 7 2009", 200)
+
@@ -0,0 +1,35 @@
+require "rubygems"
+require "feedzirra"
+require "chronic"
+
+module Rosy
+ class Parse
+ def self.get_updates(feed, from, to, chr_limit)
+ @feed = feed
+ @from = Chronic.parse(from)
+ @to = Chronic.parse(to)
+ @range = @from..@to
+
+ parsed = Feedzirra::Feed.fetch_and_parse(@feed)
+
+ updated_entries = []
+
+ # Narrow entries in date range
+ parsed.entries.each do |entry|
+ content = entry.content || entry.summary
+ if (entry.published >= @from) && (entry.published <= @to) && (content.length >= chr_limit)
+ updated_entries << entry
+ end
+ end
+ return updated_entries
+ end
+
+ def self.get_multiple_updates(feeds, from, to, chr_limit)
+ updates = []
+ feeds.each do |feed|
+ updates << self.get_updates(feed, from, to, chr_limit)
+ end
+ return updates
+ end
+ end
+end
@@ -0,0 +1,16 @@
+require "rubygems"
+require "activerecord"
+
+module Rosy
+ class Record
+ def self.record_updated_entries(parsed)
+ parsed.each do |entry|
+ Model.create( :title => entry.title,
+ :url => entry.url,
+ :author => entry.author,
+ :content => (entry.content || entry.summary),
+ :published => entry.published )
+ end
+ end
+ end
+end

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,23 @@
+require File.join(File.dirname(__FILE__), "..","spec_helper")
+
+# TODO: Bring RSS feeds out as fixture files.
+
+describe Rosy::Parse do
+ before(:all) do
+ FakeWeb.register_uri(:get, "http://feeds.feedburner.com/RubyInside", :body => load_feed("rubyinside.rss"))
+ end
+
+ it "extracts feed from Jan 1 to Jan 7 with 200 character limit" do
+ Rosy::Parse.get_updates("http://feeds.feedburner.com/RubyInside", "Jan 1 2010", "Jan 8 2010", 200).length.should == 3
+ end
+
+ it "extracts multiple feeds"
+
+ it "extracts feed with articles in summary tag but not in content"
+
+ it "extracts feed with articles in content tag but not in summary"
+
+ it "does not return feed entries out of the character limit"
+
+
+end
@@ -0,0 +1,13 @@
+require "rubygems"
+require 'spec'
+require "fakeweb"
+
+begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
+
+$LOAD_PATH << File.join(File.dirname(__FILE__),"..","lib")
+require 'rosy'
+
+
+def load_feed(filename)
+ File.read("#{File.dirname(__FILE__)}/feeds/#{filename}")
+end

0 comments on commit 7930ee8

Please sign in to comment.