lib/bbiff/executable.rb in bbiff-0.2.2 vs lib/bbiff/executable.rb in bbiff-0.3.0

- old
+ new

@@ -65,14 +65,22 @@ else fail ArgumentError end end + def get_board_settings(board) + return board.settings + rescue Bbs::Downloader::DownloadFailure => e + STDERR.puts "Warning: 以下の場所から掲示板の設定が取得できませんでした。(#{e.response.message})" + STDERR.puts board.settings_url + return {'BBS_TITLE'=>'<不明>'} + end + def start_polling(thread, start_no) out = LineIndicator.new delay = @settings.current['delay_seconds'] - board_settings = thread.board.設定 + board_settings = get_board_settings(thread.board) thread_stop = (board_settings['BBS_THREAD_STOP'] || '1000').to_i puts "#{board_settings['BBS_TITLE']} − #{thread.title}(#{thread.last})" puts " #{@settings.current['thread_url']}" @@ -102,11 +110,13 @@ end end rescue Interrupt STDERR.puts "\nユーザー割り込みにより停止" rescue => e - STDERR.puts "error occured #{e.message}" + STDERR.puts "error occured" + puts e.message + puts e.backtrace STDERR.puts "retrying..., ^C to quit" sleep 3 start_polling(thread, start_no) end @@ -127,27 +137,23 @@ if ARGV.size < 1 && !@settings.current['thread_url'] raise UsageError elsif ARGV.size < 1 url = @settings.current['thread_url'] + thread = Bbs::create_thread(url) else url = ARGV[0] - if url =~ %r{\Ah?ttp://jbbs.shitaraba.net/bbs/read.cgi/(\w+)/(\d+)/(\d+)/?\z} + begin + thread = Bbs::create_thread(url) @settings.current['thread_url'] = url - else + rescue puts "URLが変です" usage exit 1 end end - if url =~ %r{\Ah?ttp://jbbs.shitaraba.net/bbs/read.cgi/(\w+)/(\d+)/(\d+)/?\z} - ita = [$1, $2.to_i] - sure = $3.to_i - end - - thread = Bbs::C板.new(*ita).thread(sure) start_no = ARGV[1] ? ARGV[1].to_i : thread.last + 1 start_polling(thread, start_no) rescue UsageError usage exit 1