bbiff 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 037966c6b4adc37eb5630c02746d1c0a6ef609ed
4
- data.tar.gz: 87886e10129ef9ae257a78c52396bc0e3324ab39
3
+ metadata.gz: 8797d933872f35f189b8bb3314359f70e836beca
4
+ data.tar.gz: 8d528676d405351a60b78b35907b844c3ec5116a
5
5
  SHA512:
6
- metadata.gz: 1116585b2aa1dd80258bf3e8d99bba5cac503790539faeb5e5fea99b6bfedb9ea1601b59f0b3e061264f758a0500e62ef8f611cc5a45fc99ac974703344f9c73
7
- data.tar.gz: 7eb9d8a7d563b58cc52534604e7af91a2d40f416eb66bbe8ed5ac60cd3963030fd244d320c134e17da3c82b1b27a23aacafd0f7723f51c6e442598d89e7b3706
6
+ metadata.gz: 7c954728351a352e46a39b3cefa11b4d0971580d93b39967d4965ae00535e1e46e0fbf277e9b9b4af40698d06f971757c028a14d4046b4d43635b8d86cae6574
7
+ data.tar.gz: cd947dbca88dd1d6af438e60275417767ab208ba94d78465c9a69b75c25723046eed7d5fa732e6e8029c5b69614557473c3a6520adeb6ff4c7eb9264f3b9ef94
data/README.md CHANGED
@@ -55,6 +55,10 @@ ver 0.3.0
55
55
  * 2ちゃんねる互換掲示板に対応したつもり。
56
56
  * 日付の相対表示を辞めた。
57
57
 
58
+ ver 0.3.1
59
+ * エラー時にスタックトレースを表示しないようにした。
60
+ * ポート番号が指定してあってもURLを認識するようにした。
61
+
58
62
  ## 作者
59
63
 
60
64
  予定地 <plonk@piano.email.ne.jp>
@@ -4,6 +4,9 @@ require 'pp' if $DEBUG
4
4
 
5
5
  module Bbs
6
6
 
7
+ class NotFoundError < StandardError
8
+ end
9
+
7
10
  class Post
8
11
  class << self
9
12
  def from_s(str)
@@ -304,7 +307,7 @@ module Bbs
304
307
  def from_url(url)
305
308
  uri = URI.parse(url)
306
309
  board_name = uri.path.split('/').reject(&:empty?).first
307
- raise 'bad url' if board_name.nil?
310
+ return nil if board_name.nil?
308
311
  Board.send(:new, uri.hostname, uri.port, board_name)
309
312
  end
310
313
  end
@@ -326,7 +329,7 @@ module Bbs
326
329
  end
327
330
  end
328
331
 
329
- NICHAN_THREAD_URL_PATTERN = %r{\Ahttp://[a-zA-z\-\.]+/test/read\.cgi\/(\w+)/(\d+)($|/)}
332
+ NICHAN_THREAD_URL_PATTERN = %r{\Ahttp://[a-zA-z\-\.]+(?::\d+)/test/read\.cgi\/(\w+)/(\d+)($|/)}
330
333
 
331
334
  # 2ちゃんスレッド
332
335
  class Thread < ThreadBase
@@ -337,10 +340,10 @@ module Bbs
337
340
  uri = URI(url)
338
341
  board = Board.send(:new, uri.hostname, uri.port, board_name)
339
342
  thread = board.thread(thread_num)
340
- raise 'no such thread' if thread.nil?
343
+ raise NotFoundError, 'no such thread' if thread.nil?
341
344
  return thread
342
345
  else
343
- raise 'bad URL'
346
+ return nil
344
347
  end
345
348
  end
346
349
 
@@ -10,9 +10,12 @@ class Executable
10
10
  def initialize(out = STDOUT)
11
11
  @width = 0
12
12
  @out = out
13
+ @closed = false
13
14
  end
14
15
 
15
16
  def set_line(str)
17
+ raise_if_closed!
18
+
16
19
  clear
17
20
  if str[-1] == "\n"
18
21
  if str.rindex("\n") != str.size-1 || str.index("\n") < str.rindex("\n")
@@ -28,20 +31,41 @@ class Executable
28
31
  end
29
32
 
30
33
  def newline
34
+ raise_if_closed!
35
+
31
36
  @out.print "\n"
32
37
  @width = 0
33
38
  end
34
39
 
35
40
  def clear
41
+ raise_if_closed!
42
+
36
43
  @out.print "\r#{' ' * @width}\r"
37
44
  @width = 0
38
45
  end
39
46
 
40
47
  def puts(str)
48
+ raise_if_closed!
49
+
41
50
  set_line(str)
42
51
  newline
43
52
  end
44
53
 
54
+ def raise_if_closed!
55
+ if @closed
56
+ raise 'Closed LineIndicator'
57
+ end
58
+ end
59
+
60
+ def close
61
+ if @closed
62
+ raise 'already closed LineIndicator'
63
+ else
64
+ @out.puts if @width > 0
65
+ @closed = true
66
+ end
67
+ end
68
+
45
69
  private
46
70
 
47
71
  def mbswidth(str)
@@ -75,48 +99,54 @@ class Executable
75
99
  return {'BBS_TITLE'=>'<不明>'}
76
100
  end
77
101
 
102
+ RETRY_INTERVAL_SECONDS = 3
103
+
78
104
  def start_polling(thread, start_no)
79
105
  out = LineIndicator.new
80
- delay = @settings.current['delay_seconds']
81
- board_settings = get_board_settings(thread.board)
82
- thread_stop = (board_settings['BBS_THREAD_STOP'] || '1000').to_i
106
+ begin
107
+ delay = @settings.current['delay_seconds']
108
+ board_settings = get_board_settings(thread.board)
109
+ thread_stop = (board_settings['BBS_THREAD_STOP'] || '1000').to_i
83
110
 
84
- puts "#{board_settings['BBS_TITLE']} − #{thread.title}(#{thread.last})"
85
- puts " #{@settings.current['thread_url']}"
111
+ puts "#{board_settings['BBS_TITLE']} − #{thread.title}(#{thread.last})"
112
+ puts " #{@settings.current['thread_url']}"
86
113
 
87
- loop do
88
- out.set_line "#{thread.title}(#{thread.last}) 新着レス確認中"
114
+ loop do
115
+ out.set_line "#{thread.title}(#{thread.last}) 新着レス確認中"
89
116
 
90
- thread.posts(parse_range("#{start_no}-")).each do |post|
91
- out.puts "-----"
92
- puts render_post(post)
117
+ thread.posts(parse_range("#{start_no}-")).each do |post|
118
+ out.puts "-----"
119
+ puts render_post(post)
93
120
 
94
- system(@settings.current['bbiff_show'],
95
- thread.title, post.to_s)
121
+ system(@settings.current['bbiff_show'],
122
+ thread.title, post.to_s)
96
123
 
97
- sleep 1
98
- end
124
+ sleep 1
125
+ end
99
126
 
100
- start_no = thread.last + 1
101
- if start_no >= thread_stop
102
- out.puts "スレッドストップ"
103
- break
104
- end
127
+ start_no = thread.last + 1
128
+ if start_no >= thread_stop
129
+ out.puts "スレッドストップ"
130
+ break
131
+ end
105
132
 
106
- delay.times do |i|
107
- j = i + 1
108
- out.set_line "#{thread.title}(#{thread.last}) 待機中 [#{'.'*j}#{' '*(delay - j)}]"
109
- sleep 1
133
+ delay.times do |i|
134
+ j = i + 1
135
+ out.set_line "#{thread.title}(#{thread.last}) 待機中 [#{'.'*j}#{' '*(delay - j)}]"
136
+ sleep 1
137
+ end
110
138
  end
139
+ ensure
140
+ out.close
111
141
  end
112
142
  rescue Interrupt
113
- STDERR.puts "\nユーザー割り込みにより停止"
143
+ STDERR.puts "ユーザー割り込みにより停止"
114
144
  rescue => e
115
- STDERR.puts "error occured"
116
- puts e.message
117
- puts e.backtrace
118
- STDERR.puts "retrying..., ^C to quit"
119
- sleep 3
145
+ STDERR.print "Error: "
146
+ STDERR.puts e.message
147
+ STDERR.puts e.backtrace if $DEBUG
148
+ STDERR.puts "#{RETRY_INTERVAL_SECONDS}秒後にリトライ"
149
+ sleep RETRY_INTERVAL_SECONDS
120
150
  start_polling(thread, start_no)
121
151
  end
122
152
 
@@ -139,18 +169,20 @@ EOD
139
169
  raise UsageError
140
170
  elsif ARGV.size < 1
141
171
  url = @settings.current['thread_url']
142
- thread = Bbs::create_thread(url)
143
172
  else
144
173
  url = ARGV[0]
174
+ end
145
175
 
146
- begin
147
- thread = Bbs::create_thread(url)
148
- @settings.current['thread_url'] = url
149
- rescue
150
- puts "URLが変です"
151
- usage
152
- exit 1
153
- end
176
+ begin
177
+ thread = Bbs::create_thread(url)
178
+ @settings.current['thread_url'] = url
179
+ rescue => e
180
+ STDERR.puts e
181
+ exit 1
182
+ end
183
+ if thread.nil?
184
+ STDERR.puts "スレッドのURLとして解釈できませんでした。(#{url})"
185
+ exit 1
154
186
  end
155
187
 
156
188
  start_no = ARGV[1] ? ARGV[1].to_i : thread.last + 1
data/lib/bbiff/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bbiff
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoteichi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler