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