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:

#!/usr/bin/ruby
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 = [groups, feeds]
graph_names = ["groups", "top feeds"]
groupnames.each do |g|
feeds = nnw.subscriptions[its.group.display_name.eq(g)].get
feeds.reject!{|f| f.calculated_attention_score.get < 1 }
graphs << feeds
graph_names << g
end
markup = []
graphs.each do |g|
graph_name = graph_names.shift
pc = GoogleChart::PieChart.new('500x200', graph_name, false)
g[0..9].each do |s|
name = s.display_name.get
if sub_adjustments.has_key?(name)
score = s.calculated_attention_score.get - sub_adjustments[name]
else
score = s.calculated_attention_score.get
end
@feedname = s.display_name.get.gsub(/(\"|\')/, "")
pc.data "#{@feedname} (#{score})", score
end
markup << %Q@<img src="#{pc.to_url}" height=200 width=500 alt="#{graph_name} chart" />@
end
@page = <<END_OF_PAGE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>NetNewsWire Attention Charts</title>
</head>
<body>
<% markup.each do |m|%>
<%= m %>
<% end %>
</body>
</html>
END_OF_PAGE
File.open("/Users/mph/Sites/attention/index.html", 'w') {|f| f.write(ERB.new(@page).result) }

Pingback: Start Spreadin’ the News :: dot unplanned
Pingback: We Did It That Way for a Reason :: dot unplanned