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}" log "created = #{created.inspect}"
created.each do |filename| created.each do |filename|
path = File.join(dir, filename) path = File.join(dir, filename)
title, url, _ = File.readlines(path).map(&:strip) lines = File.readlines(path).map(&:strip)
command = notify_command(title, url) 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}" log "[#{Time.now.iso8601}] #{command}"
output = `#{command}` output = `#{command}`
unless $?.success? unless $?.success?
exit 1 exit 1
end end
File.rename(path, File.join(dir, 'Archive', filename)) 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
end end
rescue Exception => e rescue Exception => e
log "#{e.class}: #{e.message}" log "#{e.class}: #{e.message}"