Last active
August 29, 2015 14:03
-
-
Save cockok/91c9ed9dfea543c8a970 to your computer and use it in GitHub Desktop.
logbook log paser
This file contains 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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
# for http://kancolle.sanaechan.net/ | |
require 'date' | |
require 'optparse' | |
# parse options | |
option_hash = {} | |
opt = OptionParser.new | |
opt.separator "Common options:" | |
begin | |
opt.on('-k kaiiki', '--kaiiki kaiiki', '海域 ex. 1-1') {|v| option_hash[:k] = v} | |
opt.on('-m target', '--mode kaihatsu|shizai|kaisen|kenzou|ensei', '表示ログ') {|v| option_hash[:m] = v} | |
opt.on('-a', '--all', 'すべてのログ表示') {|v| option_hash[:a] = v} | |
opt.on('-d date', '--date YYYY-MM-DD', '対象日') {|v| option_hash[:d] = v} | |
opt.on('-b', '--boss', '海域ボスのみ表示') {|v| option_hash[:b] = v} | |
opt.on('-o', '--oryokuru', 'オリョクルもういやでち') {|v| option_hash[:o] = v} | |
opt.on('-s', '--short', '日付、海域、評価、遭遇艦隊名') {|v| option_hash[:s] = v} | |
opt.on('-h', '--help', 'ヘルプ') {|v| raige} | |
opt.parse!(ARGV) | |
rescue | |
puts opt | |
exit | |
end | |
filename = "海戦・ドロップ報告書.csv"; | |
short = "| cut -f1-7 -d ','" | |
options = "" | |
kaiiki = {"1-1" => "鎮守府正面海域", | |
"1-2" => "南西諸島沖", | |
"1-3" => "製油所地帯沿岸", | |
"1-4" => "南西諸島防衛線", | |
"1-5" => "鎮守府近海", | |
"2-1" => "カムラン半島", | |
"2-2" => "バシー島沖", | |
"2-3" => "東部オリョール海", | |
"2-4" => "沖ノ島海域", | |
"2-5" => "沖ノ島沖", | |
"3-1" => "モーレイ海", | |
"3-2" => "キス島沖", | |
"3-3" => "アルフォンシーノ方面", | |
"3-4" => "北方海域全域", | |
"3-5" => "", | |
"4-1" => "ジャム島攻略作戦", | |
"4-2" => "カレー洋制圧戦", | |
"4-3" => "リランカ島空襲", | |
"4-4" => "カスガダマ沖海戦", | |
"4-5" => "", | |
"5-1" => "南方海域前面", | |
"5-2" => "珊瑚諸島沖", | |
"5-3" => "サブ島沖海域", | |
"5-4" => "サーモン海域", | |
"5-5" => "サーモン海域北方", | |
"E-1" => "", | |
"E-2" => "北方AL海域", | |
"E-3" => "", | |
"E-4" => "", | |
"E-5" => "", | |
"E-6" => "" | |
}; | |
# date option | |
if (!option_hash.key?(:a)) then | |
if (!option_hash.key?(:t)) then | |
t = Time.now | |
# parse date | |
if option_hash.key?(:d) then | |
d = Date.parse(option_hash[:d]) | |
target_day = d | |
next_day = d + 1 | |
else | |
d = Date.parse(t.strftime("%F")) | |
# target days | |
if (t.hour >= 5) then | |
target_day = d | |
next_day = d + 1 | |
else | |
target_day = d - 1 | |
next_day = d | |
end | |
end | |
options += "| grep \"\\(#{target_day} \\(0[6-9]\\|[12][0-9]\\)\\|#{next_day} 0[0-5]\\)\"" | |
end | |
end | |
# oryokuru | |
if (option_hash.key?(:o)) then | |
options += "|grep 東部オリョール海" | |
end | |
# boss | |
if (option_hash.key?(:b)) then | |
options += "|grep \"主力\"" | |
end | |
if (option_hash.key?(:m)) then | |
case option_hash[:m] | |
when "ensei" then | |
filename = "遠征報告書.csv" | |
when "kaihatsu" then | |
filename = "開発報告書.csv" | |
when "shizai" then | |
filename = "資材ログ.csv" | |
when "kaisen" then | |
filename = "海戦・ドロップ報告書.csv" | |
when "kenzou" then | |
filename = "建造報告書.csv" | |
end | |
end | |
# short | |
if (option_hash.key?(:s)) then | |
options += short | |
end | |
# 海域 | |
if (option_hash.key?(:k)) then | |
if (kaiiki.has_key?(option_hash[:k])) then | |
options += "| grep \"#{kaiiki[option_hash[:k]]}\"" | |
end | |
end | |
filepath = "~/Dropbox/logbook/#{filename}" | |
result = `cat #{filepath} | iconv -f SHIFT_JIS -t UTF-8#{options}` | |
puts result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment