#!/usr/bin/env ruby -Ks
=begin
= ログ変換 (HTML->Log)
HTML2Log old ver.
LogScriptのajito.htmlファイルからログ(lydia形式)を作ります。
そしてtime形式(CSV/tab)に変換します。
=end
require 'date'
require 'gvglib.rb'
# 変換ファイルのあるディレクトリ(フォルダ)
# ログも同じ場所で作成される。
dir = "./ajito/"
prefix = "freya" # 接頭(ワールド名)
suffix = "_ajito.html" # 接尾
def log_read_ajito(path)
file = File.open(path)
server = 'freya' # サーバー名
ln = []
line = fortname = fortarea = now_line = now_fortname = ""
fortnumber = count = before_count = fort_breakcount = 0
fortcode = 1
# タグの除去と整形
while line = file.gets
line = line.gsub(/<(.+?)>/, "\t").gsub(/\t+/, "\t")
line = line.gsub(/\t$/, '').gsub(/^\s+/, '')
line = line.gsub(/砦別戦績/, '').gsub(/ギルド別戦績/, '')
line = line.gsub(/ランキング/, '').gsub(/HOME/, '')
line = line.gsub(/最終的な砦主は\[.+/, '').gsub(/陥落時刻/, '')
line = line.gsub(/陥落に要した.+/, '').gsub(/総陥落回数.+/, '')
line = line.gsub(/奪取したギルド名/, '').gsub(/平均保持時間/, '')
line = line.gsub(/^陥落後奪回/, '').gsub(/^完全防衛/, '')
line = line.gsub(/^#{server}.+/, '').gsub(/^\t/, '').gsub(/^\n/, '')
# サーバーが強制的に付ける文字列削除(ジオシティなら 'geovisit();'
line = line.gsub(/geovisit\(\)\;\n/, '')
if line =~ /^陥落回数(\d+)/
fort_breakcount = $1
end
line = line.gsub(/^陥落回数.+/, '')
now_line = line.chomp
for area in 0 ... ROW
for number in 0 ... COLUMN
fortarea = getfortarea(area, fortcode)
fortnumber = (number + 1).to_s
fortname = fortarea + " " + fortnumber # 砦名
if now_line == fortname
now_fortname = fortname
before_count = count
end
end
end
unless before_count == 0
ln[before_count] = now_fortname + " (" + fort_breakcount.to_s + ")\n"
end
line = line.gsub(/\t(\d\d:\d\d:\d\d)\t/, '')
line = line.gsub(/^(\d\d:\d\d:\d\d)\n/, '')
if line =~ /^#{GVG_TIME_START}/ then next end # 開始時間なら飛ばす
ln[count] = line
count += 1
end
file.close
return ln
end
def log_write_line(path, line)
file = File.open(path, "w")
limit = line.length
for count in 0 ... limit
file.print line[count]
end
file.close
end
# bijou
# 20031228 - 20050327
start_date = Date.new(2003, 12, 28) # 開始日付
end_date = Date.new(2005, 3, 27)
use_datelist = datelist_make(start_date, end_date) # 日付リスト
use_datelist = datelist_delete(use_datelist) # 中止日付リスト
limit_week = use_datelist.length
bef_fortlist = fortlist_init('', 0)
for count_week in 0 ... limit_week
#for count_week in 0 ... 1
now_ymd = use_datelist[count_week][0] # YYYYMMDD
log_path = dir + prefix + now_ymd + suffix
txt_path = dir + "lydia_" + now_ymd + ".txt"
if FileTest.exist?(log_path) == false
print "攻城戦ログ ", log_path, " は存在しません。\n"
next # 次の攻城戦ログファイルへ
end
ln = log_read_ajito(log_path)
log_write_line(txt_path, ln)
log_path = dir + "lydia_" + now_ymd + ".txt"
# 0:[時刻] 1:[砦地域] 2:[砦番号] 3:[ギルド名] (四次元配列)
fortlog = [] # 配列の初期化
fortlog = log_read_format(log_path) # 攻城戦ログの読み込み
# print "-- 攻城戦ログを読み込みました。\n"
x = y = 0 # イテレータ変数の事前宣言(高速化用)
timesortlist = fortlog.sort # {|x, y| x[0] <=> y[0]} # 時系列のソート
# 攻城戦ログ
timefile = dir + "time_" + now_ymd + ".txt" # タブコードは""で囲まないといけない
log_write_format(timefile, bef_fortlist, timesortlist)
# print "-- テキスト(tab)形式でログを書き込みました。\n"
end
exit