|
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
|
|---|
| 2 | here = File.dirname $0
|
|---|
| 3 | $LOAD_PATH << "#{here}/lib"
|
|---|
| 4 | require 'simple-json'
|
|---|
| 5 | require 'open-uri'
|
|---|
| 6 | require 'yaml'
|
|---|
| 7 | require 'mycabinet'
|
|---|
| 8 | require 'logger'
|
|---|
| 9 |
|
|---|
| 10 | $logger = Logger.new "#{here}/hatenahaiku-download.log"
|
|---|
| 11 | source = ARGV[0] || 'http://h.hatena.ne.jp/api/statuses/public_timeline.json'
|
|---|
| 12 | dbfile = ARGV[1] || "#{here}/hatenahaiku-public.db"
|
|---|
| 13 | open(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
|
|---|
| 23 | end
|
|---|