Last active
December 20, 2015 06:19
-
-
Save andreaseger/6084670 to your computer and use it in GitHub Desktop.
very simple rss fetcher to search for items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ruby | |
require 'open-uri' | |
require 'rss' | |
require 'pry' | |
class Feedly | |
attr_accessor :url, :store | |
def initialize url | |
@url = url | |
@store ||= fetch | |
end | |
def fetch | |
items = [] | |
open(url) do |rss| | |
feed = RSS::Parser.parse(rss) | |
items = feed.items | |
end | |
items | |
end | |
def log item | |
puts item.title, | |
item.itunes_subtitle, | |
item.enclosure.url, | |
item.pubDate, | |
'=-'*15 | |
end | |
# def search t, since=nil | |
# items = store.select{ |item| item.pubDate > since } if since | |
def search t | |
store.each.with_index{|e| | |
full_text = [e.title, e.description].join(' ') | |
log store[i] if full_text.match(/.*#{t}.*/i) | |
} | |
end | |
end | |
#feedly = Feedly.new 'http://nerdist.libsyn.com/rss' | |
feedly = Feedly.new ARGV[0] | |
feedly.search ARGV[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment