Created
November 28, 2010 14:02
-
-
Save noqisofon/718953 to your computer and use it in GitHub Desktop.
Opera の ADR 形式のファイルを split する Ruby スクリプト。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
# -*- encoding: shift_jis -*- | |
# file: notesplit.rb | |
Encoding.default_external = Encoding::UTF_8 | |
# ユーザー名。 | |
USER_NAME = ENV["USERNAME"] | |
# ノートが入ってるファイルへのパス。 | |
NOTE_PATH = "C:/Documents and Settings/#{USER_NAME}/Application Data/Opera/Opera/notes.adr" | |
OUT_PATH = "./notes" | |
note_hashs = [] | |
note_hash = {} | |
File.open( NOTE_PATH, "r" ) do |output| | |
output.each_line do |line| | |
# Shift_JIS に変換して行末の改行を取り除きます。 | |
line.encode( 'shift_jis' ).chomp! | |
# 1 行目だったり、2 行目だったりしたときはスキップします。 | |
next if line =~ /Opera Hotlist version/ || line =~/Options:/ | |
if line =~ /^\n$/ then | |
note_hashs << note_hash unless note_hash.empty? | |
end | |
next if line =~ /^-/ | |
if line =~ /#NOTE/ || line =~ /#FOLDER/ then | |
note_hash = { "type" => line.gsub( /^#/, "" ).chomp } | |
elsif (r = line =~ /^\t/) == 0 | |
second_eq = line.index( "=" ) | |
kav = [ line.slice( r + 1, second_eq - 1 ), line.slice( second_eq + 1, line.length ) ] | |
note_hash[kav.first.downcase] = kav.last.chomp | |
end | |
end | |
end | |
Dir.mkdir( OUT_PATH ) unless Dir.exists? OUT_PATH | |
note_hashs.each do |note| | |
next if note["type"] == "FOLDER" | |
File.open( "#{OUT_PATH}/#{note['uniqueid']}.note", "w" ) do |input| | |
note.each do |k,v| | |
input.puts "#{k}: #{v}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment