ldclip-0.0.3をリリースしました

  • インストール
gem install ldclip
  • 変更点

一部の文字列を含むurlの操作ができないバグを修正しました。

  • 詳細な説明

こちらを( ゚д゚)ノドゾー
http://d.hatena.ne.jp/utadaq/20080211

ldclipの使用サンプル

あるタグを全て変更する

  • 使用法

@idと@apikeyのところを打ち変えて、
引数1に変更対象のタグ、引数2に変更後のタグを入れてください。

$KCODE = 'u'
require "ldclip"
require "nkf"
require "pp"
require "rexml/document"

@beforetag = ARGV[0]
@aftertag  = ARGV[1]

@id = 'your id'
@apikey = 'your apikey'

post = Struct.new("Post", :href, :description, :extended, :time, :tag)
@ldc = Ldclip.new(@id,@apikey)

doc = REXML::Document.new(@ldc.get({:tag => @beforetag}))
posts = []
doc.elements.each('posts/post') do |e|
	posts << post.new(	e.attributes['href'],
					    NKF.nkf('-w',e.attributes['description']),
					    NKF.nkf('-w',e.attributes['extended']),
						e.attributes['time'],
					    NKF.nkf('-w',e.attributes['tag']))
end

posts.each do |change|
	p @ldc.add(change.href,change.description,
		{ :extended => change.extended,
		  :tags => change.tag.gsub(@beforetag,@aftertag)
		}
	)
end
  • 注意

自分は大丈夫でしたが、あなたの環境ではクリップ情報がすっ飛ぶ可能性も否定できません。
実行する前には、バックアップを取るなどの対処をしてください。

現在登録されているclipをexcelファイルに取得する(windows only)

  • 前提

windowsで、excelがインストールされている必要があります。

  • 使用法

@idと@apikeyのところを打ち変えて、スクリプトをそのまま実行すると
C:\test1.xlsというファイルが作成されます。
件数が多いと処理に時間がかかります。
1つ目のシートにclipの詳細、2つめのシートに
tagの使用件数の集計が記録されいます。
tagの整理をするために、どんなタグを使用しているかが知りたくて、作ったスクリプトです。

$KCODE = 'u'
require "ldclip"
require "nkf"
require "pp"
require "win32ole"
require "rexml/document"

@id = 'your livedoor id'
@apikey = 'your api key'

post = Struct.new("Post", :href, :description, :extended, :time, :tag)

@ldc = Ldclip.new(@id,@apikey)

doc = REXML::Document.new(@ldc.all)
posts = []
doc.elements.each('posts/post') do |e|
	posts << post.new(	e.attributes['href'],
					    NKF.nkf('-s',e.attributes['description']),
					    NKF.nkf('-s',e.attributes['extended']),
						e.attributes['time'],
					    NKF.nkf('-s',e.attributes['tag']))
end

excel = WIN32OLE.new('Excel.Application')
#excel.visible = true
excel.visible = false
excel.workbooks.add

wb = excel.workbooks(1)
ws = wb.sheets(1)

ws.cells(1,1).value = 'url'
ws.cells(1,2).value = 'タイトル'
ws.cells(1,3).value = 'コメント'
ws.cells(1,4).value = 'time'
ws.cells(1,5).value = 'tag'

i = 2
taghash = Hash.new(0)
posts.each do |e|
	ws.cells(i,1).value = e.href
	ws.cells(i,2).value = e.description
	ws.cells(i,3).value = e.extended
	ws.cells(i,4).value = e.time
	tagcount = 0
	e.tag.split(" ").each do |ee|
		ws.cells(i,5 + tagcount).value = ee
		tagcount += 1
		taghash[ee] += 1
	end
	i += 1
end

ws2 = wb.sheets(2)
ws2.activate

j = 1
taghash.sort.each do |h,e|
	ws2.cells(j,1).value = h
	ws2.cells(j,2).value = e
	j += 1
end

wb.saveas({'filename' => 'C:\test1.xls'})
excel.quit

ldclip-0.0.2をリリースしました

  • 概要

livedoorclipAPIを、rubyから操作しやすいようにしたライブラリです。

  • インストール
gem install ldclip
  • 簡単な使用法

ライブドアIDと、apikeyをこのurlから獲得します。
http://clip.livedoor.com/config/api

  • 基本的な使用方法
  @ldc = Ldclip.new(@id,@apikey)

  @ldc.update               # 最終更新日を獲得します
                            #
  @ldc.get(options = {})    # クリップ情報を取得します。 
                            # optionsで絞り条件を定義できます。
                            #  :tag         タグ
                            #
  @ldc.recent(options = {}) # 最近クリップしたクリップ情報を取得します。 
                            # optionsで絞り条件を定義できます。
                            #  :tag         タグ
                            #
  @ldc.all(options = {})    # 最近クリップしたクリップ情報を全件取得します。 
                            # optionsで絞り条件を定義できます。
                            #  :tag         タグ
                            #
  @ldc.add(url, description,# クリップを追加/更新します
           options = {})    # descriptionには、タイトルを設定します(必須)
                            # optionsでその他の条件を設定します。
                            #  :extended    コメント
                            #  :tags        タグ(スペース区切)
                            # 

(詳細は、ソースや
http://wiki.livedoor.jp/staff_clip/d/API%2c%20delicious%20compatible
を参照してください。)

newgemsで作成した雛形からパッケージを作ろうとしてエラー

以下のサイトを参考にして、rubygems用のパッケージを作成しています。
http://d.hatena.ne.jp/secondlife/20061106/1162785661
雛形のlib/[app name].rbを編集して
機能を作成後に、パッケージを作成しようとすると、エラーがでました。
そのエラーを回避したのが、以下の記録です

    • 環境
[6941]% ruby -v                                                                                                                 [/usr/ports/devel/subversion]
ruby 1.8.6 (2007-09-24 patchlevel 111) [amd64-freebsd6]
[6942]% rake --version                                                                                                          [/usr/ports/devel/subversion]
rake, version 0.8.1
[6943]% newgem -v                                                                                                               [/usr/ports/devel/subversion]
newgem 0.16.1
[6944]%            
    • 現象
[ERROR:1]% rake package --trace                                                                                                [/home/utadaq/work/ttt/sample_app]
(in /home/utadaq/work/ttt/sample_app)
rake aborted!
sample_app is not a module
./config/../lib/sample_app/version.rb:1
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
./config/hoe.rb:1
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/home/utadaq/work/ttt/sample_app/Rakefile:2
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:2149:in `load'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:2149:in `raw_load_rakefile'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1897:in `load_rakefile'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1896:in `load_rakefile'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1880:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31
/usr/local/bin/rake:16:in `load'
/usr/local/bin/rake:16
    • 原因

モジュールではなく、クラスを作成していた場合、
lib/[app name]/version.rb
のファイルを書き換える必要

#module sample_app #:nodoc: <- ココをコメントアウト
class sample_app #:nodoc:
  module VERSION #:nodoc:
    MAJOR = 0
    MINOR = 0
    TINY  = 1

    STRING = [MAJOR, MINOR, TINY].join('.')
  end
end

コレでパッケージは作られましたが、
この対処が正しいかは自信なし。。。

    • 追記

rubyのmoduleについて、どうもはっきり解ってないんだよなぁ。。。

とか、かなり理解があやふや。