<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,14 +4,21 @@
 # Use it against an HTTP log to find out who points directly towards your files
 
 require 'set'
+require 'date'
 
 class DamnHotlinkers
   MATCH_URI = /\.(jpg|jpeg|png|gif|mp3|ogg|mov|flv|mpeg|swf|avi)$/
+  IGNORE_REF = Regexp.compile %w(
+    http://www.google.com/reader
+    http://images.search.yahoo.com
+    /search?q=cache:
+  ).map { |uri| Regexp.escape uri }.join('|')
 
   attr_reader :leeches
 
-  def initialize
+  def initialize(days_ago = nil)
     @leeches = Hash.new { |h,k| h[k] = Set.new } # handy hash defaults to empty Set
+    @min_date = days_ago.nil? ? nil : Date.today - days_ago
   end
 
   # Add leeches from an Apache-like HTTP logfile
@@ -27,7 +34,9 @@ class DamnHotlinkers
 
       ref = split[10]
       ref = ref[1..ref.length-2] rescue next # unquote the referrer
-      next if ref == &quot;-&quot; or ref =~ /:\/\/#{domain}/
+      next if ref == &quot;-&quot; or ref =~ /:\/\/#{domain}/ or ref =~ IGNORE_REF
+
+      next if !@min_date.nil? and Date.parse(split[3]) &lt; @min_date
 
       @leeches[uri].add ref
     end
@@ -35,16 +44,39 @@ class DamnHotlinkers
   end
 
   # Pretty representation of sorted leeches
-  def to_s
+  def to_s(rep = nil)
+    return to_html if rep == :html
     leeches.sort.collect do |uri, referrers|
       [uri] + referrers.sort.collect { |ref| &quot;  -&gt; #{ref}&quot; }
     end.join(&quot;\n&quot;)
   end
+
+  # Same thing with a little more markup
+  def to_html
+    lis = leeches.sort.collect do |uri, referrers|
+      refs = referrers.sort.collect { |ref| &quot;&lt;li&gt;&lt;a href='#{ref}'&gt;#{ref}&lt;/a&gt;&lt;/li&gt;\n&quot; }
+      &quot;&lt;li&gt;&lt;a href='#{uri}'&gt;#{uri}&lt;/a&gt;&lt;ul&gt;#{refs}&lt;/ul&gt;&lt;/li&gt;\n&quot;
+    end
+    &quot;&lt;ul&gt;#{lis}&lt;/ul&gt;&quot;
+  end
 end
 
 if __FILE__ == $0
-  abort &quot;Usage: #{$0} file.log [file2.log ...]&quot; if ARGV.empty?
-  damn_them = DamnHotlinkers.new
+  days_ago = nil
+  if ARGV.first =~ /^--days=(\d+)$/
+    days_ago = $1.to_i
+    ARGV.shift
+  end
+
+  representation = nil
+  if ARGV.first == &quot;--html&quot;
+    representation = :html
+    ARGV.shift
+  end
+
+  abort &quot;Usage: #{$0} [--days=N] [--html] file.log [file2.log ...]&quot; if ARGV.empty?
+
+  damn_them = DamnHotlinkers.new(days_ago)
   ARGV.each { |arg| damn_them.load(arg) }
-  puts damn_them
+  puts damn_them.to_s(representation)
 end</diff>
      <filename>damn_hotlinkers.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>99b605b7c0b673b1bb1ecb700b892128fdf9b1cb</id>
    </parent>
  </parents>
  <author>
    <name>Sunny</name>
    <email>sunny@bearnaise.net</email>
  </author>
  <url>http://github.com/sunny/damn_hotlinkers/commit/a895b88c862cca2b98735e5a493d59a5dd367fd5</url>
  <id>a895b88c862cca2b98735e5a493d59a5dd367fd5</id>
  <committed-date>2008-06-26T01:07:56-07:00</committed-date>
  <authored-date>2008-06-26T01:07:56-07:00</authored-date>
  <message>Added an html representation, an argument to limit to the N days and a list of known referrers not to take care of</message>
  <tree>b4fb51c090e74ef99eaccd9094630e4bb1e0ce78</tree>
  <committer>
    <name>Sunny</name>
    <email>sunny@bearnaise.net</email>
  </committer>
</commit>
