#! /usr/bin/env ruby # # bulkplot - a tool to plot hit counts using bulkfeeds.net. # # Copyright (C) 2003 Satoru Takabayashi # All rights reserved. # This is free software with ABSOLUTELY NO WARRANTY. # # You can redistribute it and/or modify it under the terms of # the GNU General Public License version 2. # require 'mingchart' require 'cgi' require 'net/http' require 'rexml/document' def get_hit_count (keyword) response = nil Net::HTTP.start("bulkfeeds.net", 80) {|http| query = CGI.escape(keyword) format = path = sprintf("/app/search2.rdf?q=%s", query) response = http.get2(path) } doc = REXML::Document.new(response.body) count = doc.elements.to_a("rdf:RDF/channel/bulkfeeds:total").first.text return count.to_i end def draw (data) chart = MingChart.new(:flash_font => "EfontSerifB.fdb", :x_time_scale => true, :font_size => 42, :x_time_scale_format => "%m/%d" ) chart.add_data(data) chart.draw chart.save("bulkplot.swf") end def main puts "Usage: bulkplot KEYWORD" if ARGV.length != 1 keyword = ARGV.shift count = get_hit_count(keyword) File.open("bulkplot.dat", "a") {|f| f.printf("%d %d\n", Time.now.to_i, count) } data = File.new("bulkplot.dat").readlines.map {|line| line.split.map {|x| x.to_i } } draw(data) end main