From 1b67c692c10dfba66ab99eb5c309206399d1291e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 27 Mar 2014 05:02:52 -0400 Subject: [PATCH] Add hostname-specific scripts and ruby version of prowl-rss --- Gemfile | 4 +++ bin/callisto/watch-rss | 57 ++++++++++++++++++++++++++++++++++++++++++ zsh/paths | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Gemfile create mode 100644 bin/callisto/watch-rss diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..66836109 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +gem 'prowl' +gem 'simple-rss' +gem 'ruby-growl' diff --git a/bin/callisto/watch-rss b/bin/callisto/watch-rss new file mode 100644 index 00000000..bb98ffa6 --- /dev/null +++ b/bin/callisto/watch-rss @@ -0,0 +1,57 @@ +#!/usr/bin/env ruby + +# A quick script to watch a list of RSS feeds and report new entries +# to Growl, which is chained to Prowl and my home network. Never miss +# a notification again! + +# require 'prowl' +require 'net/http' +require 'simple-rss' +require 'ruby-growl' + +GUID_FILE = "#{Dir.home}/.watch-rss" +FEEDS_URL = "https://dl.dropboxusercontent.com/u/2908279/public/feeds" + +def open_url(uri) + Net::HTTP.get(URI(uri)) +end + +begin + + guids = File.exists?(GUID_FILE) ? File.open(GUID_FILE).read.split("\n") : [] + feeds = open_url(FEEDS_URL).split("\n") + + g = Growl.new("localhost", "RSS Watcher") + g.add_notification("RSS Watcher") + + feeds.each do |feed| + url,terms = feed.split("|") + + feed = SimpleRSS.parse(open_url(url)) + feed.items.each do |item| + + guid = item.id || item.link + if not terms.nil? and not item.title.index(terms) + p "Skipped: #{item.title}" + next + end + + unless guids.include? guid + g.notify("RSS Watcher", "New RSS entry!", "#{item.title}") + + guids << guid + + p "Found: #{item.title}" + else + p "Ignored: #{item.title}" + end + + end + + end + + File.open(GUID_FILE, 'w').write(guids.join("\n")) +rescue Exception => e + STDERR.puts e.message + # STDERR.puts e.backtrace.inspect.join("\n") +end diff --git a/zsh/paths b/zsh/paths index d4435634..c257aead 100644 --- a/zsh/paths +++ b/zsh/paths @@ -11,7 +11,7 @@ if [ -e /usr/local/bin/brew ]; then fi PATH=$HOME/.rvm/bin:$PATH +[ -d $HOME/.dotfiles/bin/`hostname` ] && PATH=$HOME/.dotfiles/bin/`hostname`:$PATH PATH=$HOME/.dotfiles/bin:$PATH -PATH=$HOME/Dropbox/dev/bin:$PATH # vim:set ft=zsh: