#!/usr/local/bin/ruby
# Usage : ruby update2.rb index-j.htmx > index-j.html
#ものすごーくlocalというか私カスタムなプログラム
#file内の「href」と「YYMMDD:UP」という文字列を適当に拾ってきて、
#YYMMDDをfileの更新時刻に置換。
#色とかもちびちび変える。「NEW!」とかもつける。
flag_debug = true # for-debug
mode = "index-j"
#mode = "inlink"
newhead1 = newtail1 = newhead7 = newtail7 = ""
##### load config file #####
=begin
if ARGV[0].nil?
$stderr.puts "ERR; please set config-file."
exit(1)
end
load(ARGV[0])
=end
##### option read #####
filename = ""
if ARGV[0] != nil
filename = ARGV[0]
end
if !File.exist?(filename)
$stderr.puts "ERR; cannot find input-file '" << filename << "'."
exit(1)
end
mode = filename.split(".")[0]
if mode == "index-j"
newhead1 = ''
newtail1 = '[NEW!]'
newhead7 = ''
newtail7 = '[NEW!]'
elsif mode == "inlink"
newhead1 = ''
newtail1 = '
[NEW!]'
newhead7 = ''
newtail7 = '
[NEW!]'
end
##### file read and replace #####
File.open(filename){ |f|
str = ""
f.each { |data|
str << data
}
list = str.split("YYMMDD:UP")
(0...(list.size - 1)).each { |i|
str = '------:UP'
data = list[i].split("href=")
if data[data.size - 1] =~ /"(.+?)"/
if File.exist?($1)
time = File.mtime($1)
str = time.strftime("%y%m%d") + ':UP'
diff = (Time.now - time).to_i / (60 * 60 * 24)
if diff < 1
str = newhead1 + str + newtail1
elsif diff < 7
str = newhead7 + str + newtail7
end
end
end
list[i] << str
# $stderr.puts "CHK; " + $1 + " - " + str
}
puts list.join
}