root/lang/ruby/echola/hatenahaiku-download.rb @ 18438

Revision 18438, 0.7 kB (checked in by whym, 5 years ago)

add logger

  • Property svn:executable set to *
Line 
1#!/usr/bin/env ruby
2here = File.dirname $0
3$LOAD_PATH << "#{here}/lib"
4require 'simple-json'
5require 'open-uri'
6require 'yaml'
7require 'mycabinet'
8require 'logger'
9
10$logger = Logger.new "#{here}/hatenahaiku-download.log"
11source = ARGV[0] || 'http://h.hatena.ne.jp/api/statuses/public_timeline.json'
12dbfile = ARGV[1] || "#{here}/hatenahaiku-public.db"
13open(source) do |io|
14  content = io.read
15  content = JsonParser.new.parse(content)
16  dbtype = MyCabinet::HDB
17  dbtype.new.open(dbfile, dbtype::OWRITER | dbtype::OCREAT | dbtype::ONOLCK) do |db|
18    $logger.info "writing entries between #{content[0]['created_at']} and #{content[-1]['created_at']} ..."
19    content.each do |item|
20      db.putasync(item.id.to_s, item.to_yaml)
21    end
22  end
23end
Note: See TracBrowser for help on using the browser.