Wrapping Up NNW Attention Tracking With Ruby

January 11th, 2009  |  Published in ruby  |  2 Comments

Well, it’s not the prettiest, but I wanted to finish the basics of my NNW feed attention tracking so I could feel free to drop it in a cron job and forget about doing much more with it.

This includes a hash for weighting some feeds that require a look to see what an entry is about vs. being able to tell from just the headline. I used erb to spit out a Web page I can drop onto lighttpd running on my MacBook:



require 'rubygems'

require 'appscript'

require 'google_chart'

require 'erb'

include Appscript

nnw = app("NetNewsWire")

# Lose NNW synthetic groups, feeds that serve some utility purpose, feeds I don't care to track

unwanted_groups = ["Clippings", "Mobile", "Flagged Items", "Latest News", "monitors", "miscfeeds", "mma", "people_blogs"]

# some feeds have opaque headlines that require a look before deciding whether to read

# this creates false "attention," so these adjustments are subtracted when the chart is generated:

sub_adjustments = {"MetaFilter" => 50, "Daring Fireball" => 20}

feeds = nnw.subscriptions[its.is_group.eq(false)].get

feeds.sort!{ |a,b| b.calculated_attention_score.get <=> a.calculated_attention_score.get}

groups = nnw.subscriptions[its.is_group.eq(true)].get

groups.reject!{|g| unwanted_groups.include?(g.display_name.get) }

groupnames = []

groups.each {|g| groupnames << g.display_name.get}

graphs = &#91;groups, feeds&#93;

graph_names = &#91;"groups", "top feeds"&#93;

groupnames.each do |g|

  feeds = nnw.subscriptions&#91;its.group.display_name.eq(g)&#93;.get

  feeds.reject!{|f| f.calculated_attention_score.get < 1 }

  graphs << feeds

  graph_names << g 


markup = &#91;&#93;

graphs.each do |g|

    graph_name = graph_names.shift

    pc = GoogleChart::PieChart.new('500x200', graph_name, false) 


    g&#91;0..9&#93;.each do |s|

      name = s.display_name.get

          if sub_adjustments.has_key?(name)  

          score = s.calculated_attention_score.get - sub_adjustments&#91;name&#93;


          score = s.calculated_attention_score.get


        @feedname = s.display_name.get.gsub(/(\"|\')/, "")

        pc.data "#{@feedname} (#{score})", score


markup << %Q@<img src="#{pc.to_url}" height=200 width=500 alt="#{graph_name} chart" />@


@page = <<END_OF_PAGE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


   <meta http-equiv="content-type" content="text/html; charset=utf-8" />

   <title>NetNewsWire Attention Charts</title>



<% markup.each do |m|%>

<%= m %> 

<% end %>




File.open("/Users/mph/Sites/attention/index.html", 'w') {|f| f.write(ERB.new(@page).result) }


  1. Start Spreadin’ the News :: dot unplanned says:

    January 19th, 2009 at 1:00 pm (#)

    […] with the last version of my NetNewsWire attentional graphing script, I dropped this […]

  2. We Did It That Way for a Reason :: dot unplanned says:

    June 3rd, 2010 at 12:37 am (#)

    […] January of last year, I’ve got an entry on how I graphed attentional data from my NetNewsWire use with Ruby with Ruby. And there’s also an entry about how easy it is to dump all of Safari’s […]

Leave a Response

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.