Changeset 1550

Show
Ignore:
Timestamp:
03/23/08 15:29:08 (8 months ago)
Author:
jm3
Message:

now pulling the top N and random N by tag

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • agitator/test/test.rb

    r1549 r1550  
    11#!/usr/local/bin/ruby 
    22require 'rexml/document' 
     3require 'digest/md5' 
    34include REXML 
    45 
     
    89DELICIOUS_API_PASSWORD = "argonaut1" 
    910DELICIOUS_API_URL = "https://" + DELICIOUS_API_USERNAME + ":" + DELICIOUS_API_PASSWORD + "@api.del.icio.us/v1/posts/all" 
     11NUM_LINKS_FOR_ALL_TAGS = 5 
    1012 
    1113RAILS_ROOT = "/home/jm/agitator/" 
     
    1517file = File.new(RAILS_ROOT + "tmp/API_cache/" + DELICIOUS_API_USERNAME + "/" + tag + ".xml") 
    1618doc = Document.new(file) 
    17 posts = doc.elements.to_a( "/posts/post" ) 
    18 puts posts.length.to_s + " links tagged " + tag 
     19links = doc.elements.to_a( "/posts/post" ) 
     20puts links.length.to_s + " links tagged " + tag 
    1921 
    20 posts.each { 
    21   |post|  
    22     puts post.attributes["description"]  
    23     puts "  " + post.attributes["href"]  
    24     puts "  " + post.attributes["tag"].gsub( / /, ", " ) + "\n\n" 
    25 
     22def who_else_saved( url ) 
     23  "http://del.icio.us/url/" + Digest::MD5.hexdigest( url ) 
     24end 
     25 
     26def dump_link( link ) 
     27  puts link.attributes["description"]  
     28  puts "  " + link.attributes["href"]  
     29  puts "  " + link.attributes["tag"].gsub( / /, ", " )  
     30  puts "  " + who_else_saved( link.attributes["href"] ) 
     31  puts "\n" 
     32end 
     33 
     34def dump_links 
     35  links.each { |link| dump_link link } 
     36end 
     37 
     38def dump_random_links( links, n ) 
     39  puts "here are " + n.to_s + ", chosen at random:" 
     40  puts "======================================" 
     41  for i in (1.. n) 
     42    dump_link( links[ rand(links.length) ] ) 
     43  end 
     44end 
     45 
     46def dump_most_recent( links, n ) 
     47  puts "here are the " + n.to_s + " most recent:" 
     48  puts "======================================" 
     49  for i in (0 .. n-1) 
     50    dump_link( links[i] ) 
     51  end 
     52end 
     53 
     54dump_random_links( links, NUM_LINKS_FOR_ALL_TAGS) 
     55dump_most_recent( links, NUM_LINKS_FOR_ALL_TAGS) 
     56 
     57exit 
     58