3
# Copyright (C) 2004 Satoru Takabayashi <satoru@namazu.org>
4
# You can redistribute it and/or modify it under GPL2.
6
# Modified by machu ( http://www.machu.jp/diary/ )
7
# 2008-03-07: adding last-modified filter with -a and -b option
10
after_date = Time.at(0)
11
before_date = Time.now
14
opt = OptionParser.new
15
opt.on('-a AFTER_HOUR') {|v|
16
after_date = Time.at(Time.now - 60 * 60 * v.to_i)
18
opt.on('-b BEFORE_HOUR') {|v|
19
before_date = Time.at(Time.now - 60 * 60 * v.to_i)
26
puts "Usage: tdiary-comment-clean [-a AFTER_HOUR] [-b BEFORE_HOUR] PATTERN FILE..." if ARGV.length == 0
27
pattern = Regexp.new(ARGV.shift)
31
attr_accessor :body, :date
38
if body.match(/^Last-Modified: (\d+)$/)
39
@date = Time.at($1.to_i)
46
file_names.each {|file_name|
47
i = File.open(file_name)
54
comments.push(comment)
62
tmp_name = "tmp.#{Process.pid}"
63
File.open(tmp_name, "w") {|o|
65
comments.each {|comment|
66
if pattern.match(comment.body) and (before_date > comment.date) and (after_date < comment.date)
67
deleted_comments.push(comment)
74
File.rename(file_name, file_name + ".bak") unless test
75
File.rename(tmp_name, file_name) unless test
78
deleted_comments.each {|comment|