Wrapping Up NNW Attention Tracking With Ruby

From the archive — written 17 years ago. About old posts.

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:

<div style="text\-align:center;">![](https://media.puddingtime.org/archive/mph.puddingbowl.org/wordpress/wp-content/uploads/2009/01/attention-charts.png)</div>
<p>

[sourcecode language=‘ruby’]

!/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@ `![]({pc.to_url})` @

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) }

[/sourcecode]

</p>

#attention #netnewswire #rb-appscript #ruby

Drop a line about this.