bbiff 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/bbiff/bbs_reader.rb +7 -4
- data/lib/bbiff/executable.rb +70 -38
- data/lib/bbiff/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8797d933872f35f189b8bb3314359f70e836beca
|
4
|
+
data.tar.gz: 8d528676d405351a60b78b35907b844c3ec5116a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c954728351a352e46a39b3cefa11b4d0971580d93b39967d4965ae00535e1e46e0fbf277e9b9b4af40698d06f971757c028a14d4046b4d43635b8d86cae6574
|
7
|
+
data.tar.gz: cd947dbca88dd1d6af438e60275417767ab208ba94d78465c9a69b75c25723046eed7d5fa732e6e8029c5b69614557473c3a6520adeb6ff4c7eb9264f3b9ef94
|
data/README.md
CHANGED
data/lib/bbiff/bbs_reader.rb
CHANGED
@@ -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
|
-
|
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\-\.]
|
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
|
-
|
346
|
+
return nil
|
344
347
|
end
|
345
348
|
end
|
346
349
|
|
data/lib/bbiff/executable.rb
CHANGED
@@ -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
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
85
|
-
|
111
|
+
puts "#{board_settings['BBS_TITLE']} − #{thread.title}(#{thread.last})"
|
112
|
+
puts " #{@settings.current['thread_url']}"
|
86
113
|
|
87
|
-
|
88
|
-
|
114
|
+
loop do
|
115
|
+
out.set_line "#{thread.title}(#{thread.last}) 新着レス確認中"
|
89
116
|
|
90
|
-
|
91
|
-
|
92
|
-
|
117
|
+
thread.posts(parse_range("#{start_no}-")).each do |post|
|
118
|
+
out.puts "-----"
|
119
|
+
puts render_post(post)
|
93
120
|
|
94
|
-
|
95
|
-
|
121
|
+
system(@settings.current['bbiff_show'],
|
122
|
+
thread.title, post.to_s)
|
96
123
|
|
97
|
-
|
98
|
-
|
124
|
+
sleep 1
|
125
|
+
end
|
99
126
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
127
|
+
start_no = thread.last + 1
|
128
|
+
if start_no >= thread_stop
|
129
|
+
out.puts "スレッドストップ"
|
130
|
+
break
|
131
|
+
end
|
105
132
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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 "
|
143
|
+
STDERR.puts "ユーザー割り込みにより停止"
|
114
144
|
rescue => e
|
115
|
-
STDERR.
|
116
|
-
puts e.message
|
117
|
-
puts e.backtrace
|
118
|
-
STDERR.puts "
|
119
|
-
sleep
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
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.
|
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-
|
11
|
+
date: 2016-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|