平衡点


2008/12/27

_ howm を複数ファイル分割へ戻す

changelog メモっぽく単一ファイルにしていたけれど, 流石に検索が重くなってきたので, 複数ファイルへ戻すことにする.

#!/usr/bin/env ruby
$KCODE='e'
#--- config start ---"
src = ENV['HOME'] + "/work/howm/ChangeLog.howm"
outdir = ENV['HOME'] + "/work/howm/"
#--- config end ---"
unless File.exist?(src)
  puts "ChangeLog files does not given"
  exit 0
end
# howm の形式の指定
datef = '\d{4}-\d{2}-\d{2}'
timef = '\d{2}:\d{2}:\d{2}'
timelinef = datef + '\s' + timef
# 日付毎に分割
cl = File.read(src).split(/(?=^\[#{timelinef}\])/m).sort
cl.each do |entries|
  entries.gsub!(/^\s+$/, "")
  dt = $1 if entries =~/\[(#{timelinef})\]/m 
  fn = $1 + "-" + $2 if dt.gsub!(/-/,"").gsub!(/:/,"") =~ /(\d{8})\s(\d{6})/
  File.open(outdir + fn + ".howm", "w"){|f|
    f.puts entries
  }
end

安易です.

ついでに howm からはてダラ用のソースへと変換するスクリプトもでっちあげる.

#!/usr/bin/env ruby
$KCODE='e'
require 'tempfile'

src_dir = ENV['HOME'] + "/work/howm/"
out_dir = ENV['HOME'] + "/work/hatena/"
src = Dir.glob(src_dir+"*.howm").sort

# エントリー格納用 Hash
howm_entries = {}
# エントリーパース
src.each do |src_file|
  # 日付の取得
  yy, mm, dd = $1, $2, $3 if File.basename(src_file) =~/^(\d{4})(\d{2})(\d{2})/
  # 出力ファイル名の設定. これを Hash の key にする.
  out_fname = yy + "-" + mm + "-" +  dd + ".txt"
  # ソースの読み込み
  entry = File.open(src_file).read
  # 不要な空行を削除
  entry.gsub!(/^\s+$/,"")
  # 秘密のエントリ以外を出力
  unless entry =~ /^\=\s*p:.*/
    # howm 用の timeline を空行に(はてなダイアリでタイトルを入力しない)
    entry.gsub!(/^\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\].*$/,"")
    # ファイルへのリンクを削除
    entry.gsub!(/(\=\=\>.*?\n)/m,"")
    # 逆リンクの削除
    entry.gsub!(/(\<\=\=.*?\n)/m,"")
    # 連続した改行を \n\n に置換
    entry.gsub!(/\n\n+/m, "\n\n")
    # プラグイン関係を preformatted に
    entry.gsub!(/^\>/,"\s\>")
    entry.gsub!(/^\|/,"\s\|")
    entry.gsub!(/^\</,"\s\<")
    entry.gsub!(/^f:id/,"\sf:id")
    entry.gsub!(/^map:/,"\smap:")
    entry.gsub!(/^\<iframe:/,"\s\<iframe:")
    # 格納
    if howm_entries.key?(out_fname)
      # ださい...
      pre = howm_entries[out_fname].to_s
      new = entry + pre
      howm_entries[out_fname] = [new]
    else
      howm_entries[out_fname] = [entry]
    end
  end
end

# 出力
howm_entries.sort.each do |out_fname, entries|
  str = ""
  diaryfile = out_dir + out_fname
  if File.exists?(diaryfile)
    old = open(diaryfile).read
  end
  str = entries.to_s.gsub(/^(\=.*\:?)/,'\1'+"\n")
  rd2 = "rd2 -r rd/rd2hatena-lib"
  unless str.empty?
    IO.popen(rd2, 'r+') do |pipe|
      pipe.write(str)
      pipe.close_write
      new = pipe.read
      unless old == new 
        puts "#{diaryfile} is updated"
        File.open(diaryfile, "w"){|file|
          file.puts new
        }
      end
    end
  end
end

...いまいち. 特に以前同様, 配列に一度格納しているのがなんか嫌. ファイル数が多くなると破綻しそうな気がする.

ちなみに整形自体は, 以前いんちき臭く作成したrd2hatena-lib.rb経由で.

...日記自体はちゃんと更新できている様なので, まあいっか.

_ bluetooth 経由で聞くと音が切れる

前回(bluetoothでじたばた)の続き.

rhythumbox で音を鳴らして聞いているのだけれども, 頻繁に音が飛ぶ.

どうも処理が複数走った時に, 割り込みくらって止まっている感じだなぁ.やはり USB の bluetooth スタックだと駄目なのかな? リアルタイムカーネルにすれば良いんだろうか? うーん.

iPod で鳴らしている分には問題無いのに. なんか悔しい.


連絡先など
最近の日記
  • 2024/04/28
    • 1. CF-SR3 での生活環境構築 (できてない)
  • 2024/03/29
    • 1. Debian GNU/Linux on CF-SR3
  • 2024/03/25
    • 1. org-mode → beamer でのリスト記号の一時変更
  • 2024/03/22
    • 1. 静的htmlによるGit Repository Browser
  • 2024/02/15
    • 1. org-mode → bemaer での番号付きリスト
一覧
2006|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|02|03|04|08|09|10|11|12|
2013|01|02|03|04|05|06|08|09|10|11|12|
2014|01|02|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|09|10|
2016|02|03|
2017|01|02|03|05|06|07|09|11|12|
2018|03|06|07|10|11|12|
2019|01|02|03|04|05|07|10|12|
2020|01|02|03|04|05|08|09|10|11|12|
2021|01|02|03|05|06|07|08|09|11|12|
2022|01|02|03|04|05|06|08|10|11|12|
2023|02|03|04|06|08|09|11|12|
2024|01|02|03|04|
Back to Top ▲