create Archive dir if it doesn't exist yet

This commit is contained in:
Sami Samhuri 2014-02-25 00:39:15 -08:00
parent 4ea0a41db1
commit 575d43908f

View file

@ -45,14 +45,31 @@ def main
log "created = #{created.inspect}"
created.each do |filename|
path = File.join(dir, filename)
title, url, _ = File.readlines(path).map(&:strip)
command = notify_command(title, url)
log "[#{Time.now.iso8601}] #{command}"
output = `#{command}`
unless $?.success?
exit 1
lines = File.readlines(path).map(&:strip)
title, url = nil, nil
until (title && url) || lines.empty?
line = lines.shift
next if line == ''
if line =~ /^http/
url ||= line
else
title ||= line
end
end
if url
command = notify_command(title || url, url)
log "[#{Time.now.iso8601}] #{command}"
output = `#{command}`
unless $?.success?
exit 1
end
archive_dir = File.join(dir, 'Archive')
Dir.mkdir(archive_dir) unless File.exists?(archive_dir)
File.rename(path, File.join(archive_dir, filename))
else
log "[#{Time.now.iso8601}] Failed to find URL in #{filename}: #{File.read(path)}"
end
File.rename(path, File.join(dir, 'Archive', filename))
end
rescue Exception => e
log "#{e.class}: #{e.message}"