syobocal 0.9.0

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.
data/bin/anime ADDED
@@ -0,0 +1,47 @@
1
+ #! /usr/bin/env ruby
2
+ # coding:utf-8
3
+
4
+ require 'syobocal'
5
+
6
+ def format_time(time)
7
+ h = time.hour
8
+ h += 24 if h < 5
9
+ m = time.min
10
+
11
+ sprintf("%2d:%02d", h, m)
12
+ end
13
+
14
+ params = {"days" => "1"}
15
+ result = Syobocal::CalChk.get(params)
16
+
17
+ puts "これから放送されるアニメ@首都圏\n"
18
+
19
+ result.select{|prog|
20
+ # 現在から
21
+ st = Time.now
22
+
23
+ # 次の朝5時まで
24
+ day = Time.now.hour < 5 ? Date.today : Date.today + 1
25
+ ed = Time.new(day.year, day.month, day.day, 5)
26
+
27
+ # 首都圏のチャンネルで放送されるアニメ
28
+ syutoken_ch = [
29
+ 1, # NHK総合
30
+ 2, # NHK Eテレ
31
+ 3, # フジテレビ
32
+ 4, # 日本テレビ
33
+ 5, # TBS
34
+ 6, # テレビ朝日
35
+ 7, # テレビ東京
36
+ 8, # TVK
37
+ 13, # チバテレビ
38
+ 14, # テレ玉
39
+ 19, # TOKYO MX
40
+ ]
41
+
42
+ st < prog[:st_time] and prog[:st_time] < ed and syutoken_ch.include?(prog[:ch_id])
43
+ }.sort_by{|prog|
44
+ prog[:st_time] # 放送開始日時で降順に並べ替え
45
+ }.each{|prog|
46
+ puts "#{format_time(prog[:st_time])} [#{prog[:ch_name]}] #{prog[:title]} / #{prog[:sub_title]}"
47
+ }
data/bin/syobocal ADDED
@@ -0,0 +1,138 @@
1
+ #! /usr/bin/env ruby
2
+ # coding:utf-8
3
+
4
+ require 'syobocal'
5
+ require 'pp'
6
+
7
+ command = ARGV[0]
8
+ params = {}
9
+ params = eval(ARGV[1]) if ARGV[1]
10
+
11
+ $SYOBOCAL_STRICT = true
12
+
13
+ case command
14
+ when "CalChk"
15
+ pp Syobocal::CalChk.get(params)
16
+ when "DB::TitleLookup"
17
+ puts Syobocal::DB::TitleLookup.url(params)
18
+ result = Syobocal::DB::TitleLookup.get(params)
19
+ puts "Code: " + result.code.to_s
20
+ puts "Message: " + (result.message || "")
21
+ pp result
22
+ when "DB::ProgLookup"
23
+ puts Syobocal::DB::ProgLookup.url(params)
24
+ result = Syobocal::DB::ProgLookup.get(params)
25
+ puts "Code: " + result.code.to_s
26
+ puts "Message: " + (result.message || "")
27
+ pp result
28
+ when "DB::ChLookup"
29
+ puts Syobocal::DB::ChLookup.url(params)
30
+ result = Syobocal::DB::ChLookup.get(params)
31
+ puts "Code: " + result.code.to_s
32
+ puts "Message: " + (result.message || "")
33
+ pp result
34
+ when "DB::ChGroupLookup"
35
+ puts Syobocal::DB::ChGroupLookup.url(params)
36
+ result = Syobocal::DB::ChGroupLookup.get(params)
37
+ puts "Code: " + result.code.to_s
38
+ puts "Message: " + (result.message || "")
39
+ pp result
40
+ when "DB::TitleViewCount"
41
+ puts Syobocal::DB::TitleViewCount.url(params)
42
+ result = Syobocal::DB::TitleViewCount.get(params)
43
+ puts "Code: " + result.code.to_s
44
+ puts "Message: " + (result.message || "")
45
+ if result.code == 200
46
+ puts "Title: " + result.title
47
+ puts "Type: " + result.type
48
+ puts "Columns: " + result.columns.join(', ')
49
+ end
50
+ pp result
51
+ when "DB::TitleRankHistory"
52
+ puts Syobocal::DB::TitleRankHistory.url(params)
53
+ result = Syobocal::DB::TitleRankHistory.get(params)
54
+ puts "Code: " + result.code.to_s
55
+ puts "Message: " + (result.message || "")
56
+ if result.code == 200
57
+ puts "Title: " + result.title
58
+ puts "Type: " + result.type
59
+ puts "Columns: " + result.columns.join(', ')
60
+ end
61
+ pp result
62
+ when "DB::TitlePointHistory"
63
+ puts Syobocal::DB::TitlePointHistory.url(params)
64
+ result = Syobocal::DB::TitlePointHistory.get(params)
65
+ puts "Code: " + result.code.to_s
66
+ puts "Message: " + (result.message || "")
67
+ if result.code == 200
68
+ puts "Title: " + result.title
69
+ puts "Type: " + result.type
70
+ puts "Columns: " + result.columns.join(', ')
71
+ end
72
+ pp result
73
+ when "DB::TitlePointTop"
74
+ puts Syobocal::DB::TitlePointTop.url(params)
75
+ result = Syobocal::DB::TitlePointTop.get(params)
76
+ puts "Code: " + result.code.to_s
77
+ puts "Message: " + (result.message || "")
78
+ if result.code == 200
79
+ puts "Title: " + result.title
80
+ puts "Type: " + result.type
81
+ puts "Columns: " + result.columns.join(', ')
82
+ end
83
+ pp result
84
+ when "JSON::TitleMedium"
85
+ puts Syobocal::JSON::TitleMedium.url(params)
86
+ result = Syobocal::JSON::TitleMedium.get(params)
87
+ pp result
88
+ when "JSON::TitleLarge"
89
+ puts Syobocal::JSON::TitleLarge.url(params)
90
+ result = Syobocal::JSON::TitleLarge.get(params)
91
+ pp result
92
+ when "JSON::TitleFull"
93
+ puts Syobocal::JSON::TitleFull.url(params)
94
+ result = Syobocal::JSON::TitleFull.get(params)
95
+ pp result
96
+ when "JSON::ProgramByPID"
97
+ puts Syobocal::JSON::ProgramByPID.url(params)
98
+ result = Syobocal::JSON::ProgramByPID.get(params)
99
+ pp result
100
+ when "JSON::ProgramByCount"
101
+ puts Syobocal::JSON::ProgramByCount.url(params)
102
+ result = Syobocal::JSON::ProgramByCount.get(params)
103
+ pp result
104
+ when "JSON::ProgramByData"
105
+ puts Syobocal::JSON::ProgramByData.url(params)
106
+ result = Syobocal::JSON::ProgramByData.get(params)
107
+ pp result
108
+ when "JSON::SubTitles"
109
+ puts Syobocal::JSON::SubTitles.url(params)
110
+ result = Syobocal::JSON::SubTitles.get(params)
111
+ pp result
112
+ when "JSON::ChFilter"
113
+ puts Syobocal::JSON::ChFilter.url(params)
114
+ result = Syobocal::JSON::ChFilter.get(params)
115
+ pp result
116
+ when "JSON::ChIDFilter"
117
+ puts Syobocal::JSON::ChIDFilter.url(params)
118
+ result = Syobocal::JSON::ChIDFilter.get(params)
119
+ pp result
120
+ when "RSS"
121
+ puts Syobocal::RSS.url(params)
122
+ result = Syobocal::RSS.get(params)
123
+ puts "Title: " + result.title
124
+ puts "link: " + result.link
125
+ puts "Description: " + result.description
126
+ pp result
127
+ when "RSS2"
128
+ puts Syobocal::RSS2.url(params)
129
+ result = Syobocal::RSS2.get(params)
130
+ puts "Title: " + result.title
131
+ puts "link: " + result.link
132
+ puts "Language: " + result.dc_language
133
+ puts "PubDate: " + result.pub_date.to_s
134
+ pp result
135
+ else
136
+ $stderr.puts "Unknown command or command was not specified."
137
+ $stderr.puts "Example: syobocal CalChk"
138
+ end
data/lib/syobocal.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'open-uri'
2
+ require 'rexml/document'
3
+ require 'delegate'
4
+ require 'json'
5
+ require 'rss'
6
+
7
+ require_relative 'syobocal/util.rb'
8
+ require_relative 'syobocal/calchk.rb'
9
+ require_relative 'syobocal/db.rb'
10
+ require_relative 'syobocal/json.rb'
11
+ require_relative 'syobocal/rss.rb'
12
+ require_relative 'syobocal/rss2.rb'
@@ -0,0 +1,52 @@
1
+ module Syobocal
2
+ module CalChk
3
+ def get(params = {})
4
+ parse(open(url(params)))
5
+ end
6
+
7
+ def url(params = {})
8
+ 'http://cal.syoboi.jp/cal_chk.php' + Syobocal::Util.format_params(params)
9
+ end
10
+
11
+ def parse(xml)
12
+ xml = REXML::Document.new(xml)
13
+
14
+ result = Result.new
15
+
16
+ syobocal = xml.elements['syobocal']
17
+ result.url = syobocal.attribute("url").to_s
18
+ result.version = syobocal.attribute("version").to_s
19
+ result.last_update = Time.parse(syobocal.attribute("LastUpdate").to_s)
20
+ result.spid = syobocal.attribute("SPID").to_s
21
+ result.spname = syobocal.attribute("SPNAME").to_s
22
+
23
+ xml.elements.each('syobocal/ProgItems/ProgItem'){|item|
24
+ result << {
25
+ :pid => item.attribute("PID").to_s.to_i,
26
+ :tid => item.attribute("TID").to_s.to_i,
27
+ :st_time => Time.parse(item.attribute("StTime").to_s),
28
+ :ed_time => Time.parse(item.attribute("EdTime").to_s),
29
+ :ch_name => item.attribute("ChName").to_s,
30
+ :ch_id => item.attribute("ChID").to_s.to_i,
31
+ :count => item.attribute("Count").to_s.to_i,
32
+ :st_offset => item.attribute("StOffset").to_s.to_i,
33
+ :sub_title => item.attribute("SubTitle").to_s,
34
+ :title => item.attribute("Title").to_s,
35
+ :prog_comment => item.attribute("ProgComment").to_s
36
+ }
37
+ }
38
+
39
+ result
40
+ end
41
+
42
+ module_function :get, :url, :parse
43
+
44
+ class Result < DelegateClass(Array)
45
+ attr_accessor :url, :version, :last_update, :spid, :spname
46
+
47
+ def initialize
48
+ super([])
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,346 @@
1
+ module Syobocal
2
+ module DB
3
+ module Mapper
4
+ def map(elm)
5
+ result = {}
6
+ elm.each_element{|child|
7
+ set(result, to_snake(child.name).to_sym, child, @map[child.name])
8
+ }
9
+ result
10
+ end
11
+
12
+ def to_snake(name)
13
+ name.gsub(/([a-z])([A-Z])/){ $1 + '_' + $2 }.downcase
14
+ end
15
+
16
+ def set(hash, key, elm, type)
17
+ if elm
18
+ val = nil
19
+ if elm.text
20
+ case type
21
+ when :str
22
+ val = elm.text
23
+ when :int
24
+ val = elm.text.to_i
25
+ when :time
26
+ val = Time.parse(elm.text)
27
+ else
28
+ raise "Undefined mapping for #{key}" if $SYOBOCAL_STRICT
29
+ val = elm.text
30
+ end
31
+ end
32
+ hash[key] = val
33
+ end
34
+ end
35
+ end
36
+
37
+ module TitleLookup
38
+ def get(params = {})
39
+ parse(open(url(params)))
40
+ end
41
+
42
+ def url(params)
43
+ 'http://cal.syoboi.jp/db.php?Command=TitleLookup' + Syobocal::Util.format_params_amp(params)
44
+ end
45
+
46
+ def parse(xml)
47
+ xml = REXML::Document.new(xml)
48
+
49
+ result = LookupResult.new
50
+
51
+ result.code = xml.elements['TitleLookupResponse/Result/Code'].text.to_i
52
+ result.message = xml.elements['TitleLookupResponse/Result/Message'].text
53
+
54
+ xml.elements.each('TitleLookupResponse/TitleItems/TitleItem'){|item|
55
+ mapper = Mapper.new
56
+ result << mapper.map(item)
57
+ }
58
+
59
+ result
60
+ end
61
+
62
+ module_function :get, :url, :parse
63
+
64
+ class Mapper
65
+ include Syobocal::DB::Mapper
66
+
67
+ def initialize
68
+ @map = {
69
+ "TID" => :int,
70
+ "LastUpdate" => :time,
71
+ "Title" => :str,
72
+ "ShortTitle" => :str,
73
+ "TitleYomi" => :str,
74
+ "TitleEN" => :str,
75
+ "Comment" => :str,
76
+ "Cat" => :int,
77
+ "TitleFlag" => :int,
78
+ "FirstYear" => :int,
79
+ "FirstMonth" => :int,
80
+ "FirstEndYear" => :int,
81
+ "FirstEndMonth" => :int,
82
+ "FirstCh" => :int,
83
+ "Keywords" => :str,
84
+ "UserPoint" => :int,
85
+ "UserPointRank" => :int,
86
+ "SubTitles" => :str,
87
+ }
88
+ end
89
+ end
90
+ end
91
+
92
+ module ProgLookup
93
+ def get(params = {})
94
+ parse(open(url(params)))
95
+ end
96
+
97
+ def url(params)
98
+ 'http://cal.syoboi.jp/db.php?Command=ProgLookup' + Syobocal::Util.format_params_amp(params)
99
+ end
100
+
101
+ def parse(xml)
102
+ xml = REXML::Document.new(xml)
103
+
104
+ result = LookupResult.new
105
+
106
+ result.code = xml.elements['ProgLookupResponse/Result/Code'].text.to_i
107
+ result.message = xml.elements['ProgLookupResponse/Result/Message'].text
108
+
109
+ xml.elements.each('ProgLookupResponse/ProgItems/ProgItem'){|item|
110
+ mapper = Mapper.new
111
+ result << mapper.map(item)
112
+ }
113
+
114
+ result
115
+ end
116
+
117
+ module_function :get, :url, :parse
118
+
119
+ class Mapper
120
+ include Syobocal::DB::Mapper
121
+
122
+ def initialize
123
+ @map = {
124
+ "LastUpdate" => :time,
125
+ "PID" => :int,
126
+ "TID" => :int,
127
+ "StTime" => :time,
128
+ "StOffset" => :int,
129
+ "EdTime" => :time,
130
+ "Count" => :int,
131
+ "SubTitle" => :str,
132
+ "ProgComment" => :str,
133
+ "Flag" => :int,
134
+ "Deleted" => :int,
135
+ "Warn" => :int,
136
+ "ChID" => :int,
137
+ "Revision" => :int,
138
+ "STSubTitle" => :str,
139
+ }
140
+ end
141
+ end
142
+ end
143
+
144
+ module ChLookup
145
+ def get(params = {})
146
+ parse(open(url(params)))
147
+ end
148
+
149
+ def url(params)
150
+ 'http://cal.syoboi.jp/db.php?Command=ChLookup' + Syobocal::Util.format_params_amp(params)
151
+ end
152
+
153
+ def parse(xml)
154
+ xml = REXML::Document.new(xml)
155
+
156
+ result = LookupResult.new
157
+
158
+ result.code = xml.elements['ChLookupResponse/Result/Code'].text.to_i
159
+ result.message = xml.elements['ChLookupResponse/Result/Message'].text
160
+
161
+ xml.elements.each('ChLookupResponse/ChItems/ChItem'){|item|
162
+ mapper = Mapper.new
163
+ result << mapper.map(item)
164
+ }
165
+
166
+ result
167
+ end
168
+
169
+ module_function :get, :url, :parse
170
+
171
+ class Mapper
172
+ include Syobocal::DB::Mapper
173
+
174
+ def initialize
175
+ @map = {
176
+ "LastUpdate" => :time,
177
+ "ChID" => :int,
178
+ "ChName" => :str,
179
+ "ChiEPGName" => :str,
180
+ "ChURL" => :str,
181
+ "ChEPGURL" => :str,
182
+ "ChComment" => :str,
183
+ "ChGID" => :int,
184
+ "ChNumber" => :int,
185
+ }
186
+ end
187
+ end
188
+ end
189
+
190
+ module ChGroupLookup
191
+ def get(params = {})
192
+ parse(open(url(params)))
193
+ end
194
+
195
+ def url(params)
196
+ 'http://cal.syoboi.jp/db.php?Command=ChGroupLookup' + Syobocal::Util.format_params_amp(params)
197
+ end
198
+
199
+ def parse(xml)
200
+ xml = REXML::Document.new(xml)
201
+
202
+ result = LookupResult.new
203
+
204
+ result.code = xml.elements['ChGroupLookupResponse/Result/Code'].text.to_i
205
+ result.message = xml.elements['ChGroupLookupResponse/Result/Message'].text
206
+
207
+ xml.elements.each('ChGroupLookupResponse/ChGroupItems/ChGroupItem'){|item|
208
+ mapper = Mapper.new
209
+ result << mapper.map(item)
210
+ }
211
+
212
+ result
213
+ end
214
+
215
+ module_function :get, :url, :parse
216
+
217
+ class Mapper
218
+ include Syobocal::DB::Mapper
219
+
220
+ def initialize
221
+ @map = {
222
+ "LastUpdate" => :time,
223
+ "ChGID" => :int,
224
+ "ChGroupName" => :str,
225
+ "ChGroupComment" => :str,
226
+ "ChGroupOrder" => :int,
227
+ }
228
+ end
229
+ end
230
+ end
231
+
232
+ module TitleViewCount
233
+ def get(params = {})
234
+ parse(open(url(params)))
235
+ end
236
+
237
+ def url(params)
238
+ 'http://cal.syoboi.jp/db.php?Command=TitleViewCount' + Syobocal::Util.format_params_amp(params)
239
+ end
240
+
241
+ def parse(xml)
242
+ Syobocal::DB.parse_table_data(xml)
243
+ end
244
+
245
+ module_function :get, :url, :parse
246
+ end
247
+
248
+ module TitleRankHistory
249
+ def get(params = {})
250
+ parse(open(url(params)))
251
+ end
252
+
253
+ def url(params)
254
+ 'http://cal.syoboi.jp/db.php?Command=TitleRankHistory' + Syobocal::Util.format_params_amp(params)
255
+ end
256
+
257
+ def parse(xml)
258
+ Syobocal::DB.parse_table_data(xml)
259
+ end
260
+
261
+ module_function :get, :url, :parse
262
+ end
263
+
264
+ module TitlePointHistory
265
+ def get(params = {})
266
+ parse(open(url(params)))
267
+ end
268
+
269
+ def url(params)
270
+ 'http://cal.syoboi.jp/db.php?Command=TitlePointHistory' + Syobocal::Util.format_params_amp(params)
271
+ end
272
+
273
+ def parse(xml)
274
+ Syobocal::DB.parse_table_data(xml)
275
+ end
276
+
277
+ module_function :get, :url, :parse
278
+ end
279
+
280
+ module TitlePointTop
281
+ def get(params = {})
282
+ parse(open(url(params)))
283
+ end
284
+
285
+ def url(params)
286
+ 'http://cal.syoboi.jp/db.php?Command=TitlePointTop' + Syobocal::Util.format_params_amp(params)
287
+ end
288
+
289
+ def parse(xml)
290
+ Syobocal::DB.parse_table_data(xml)
291
+ end
292
+
293
+ module_function :get, :url, :parse
294
+ end
295
+
296
+ def self.parse_table_data(xml)
297
+ xml = REXML::Document.new(xml)
298
+
299
+ result = TableResult.new
300
+
301
+ result.code = xml.elements['TableData/Result/Code'].text.to_i
302
+ result.message = xml.elements['TableData/Result/Message'].text
303
+
304
+ result.columns = []
305
+ if result.code == 200
306
+ result.title = xml.elements['TableData/Title'].text
307
+ result.type = xml.elements['TableData/Type'].text
308
+
309
+ xml.elements.each('TableData/Columns/Value'){|item|
310
+ result.columns << item.text
311
+ }
312
+
313
+ xml.elements.each('TableData/Line'){|line|
314
+ line_data = {}
315
+ line.elements.each_with_index{|value, index|
316
+ key = result.columns[index]
317
+ if key == "Date"
318
+ line_data[key] = Date.parse(value.text)
319
+ else
320
+ line_data[key] = value.text ? value.text.to_i : nil
321
+ end
322
+ }
323
+ result << line_data
324
+ }
325
+ end
326
+
327
+ result
328
+ end
329
+
330
+ class LookupResult < DelegateClass(Array)
331
+ attr_accessor :code, :message
332
+
333
+ def initialize
334
+ super([])
335
+ end
336
+ end
337
+
338
+ class TableResult < DelegateClass(Array)
339
+ attr_accessor :code, :message, :title, :type, :columns
340
+
341
+ def initialize
342
+ super([])
343
+ end
344
+ end
345
+ end
346
+ end
@@ -0,0 +1,147 @@
1
+ module Syobocal
2
+ module JSON
3
+ module TitleMedium
4
+ def get(params = {})
5
+ parse(open(url(params)))
6
+ end
7
+
8
+ def url(params = {})
9
+ 'http://cal.syoboi.jp/json.php?Req=TitleMedium' + Syobocal::Util.format_params_amp(params)
10
+ end
11
+
12
+ def parse(json)
13
+ ::JSON.load(json)
14
+ end
15
+
16
+ module_function :get, :url, :parse
17
+ end
18
+
19
+ module TitleLarge
20
+ def get(params = {})
21
+ parse(open(url(params)))
22
+ end
23
+
24
+ def url(params = {})
25
+ 'http://cal.syoboi.jp/json.php?Req=TitleLarge' + Syobocal::Util.format_params_amp(params)
26
+ end
27
+
28
+ def parse(json)
29
+ ::JSON.load(json)
30
+ end
31
+
32
+ module_function :get, :url, :parse
33
+ end
34
+
35
+ module TitleFull
36
+ def get(params = {})
37
+ parse(open(url(params)))
38
+ end
39
+
40
+ def url(params = {})
41
+ 'http://cal.syoboi.jp/json.php?Req=TitleFull' + Syobocal::Util.format_params_amp(params)
42
+ end
43
+
44
+ def parse(json)
45
+ ::JSON.load(json)
46
+ end
47
+
48
+ module_function :get, :url, :parse
49
+ end
50
+
51
+ module ProgramByPID
52
+ def get(params = {})
53
+ parse(open(url(params)))
54
+ end
55
+
56
+ def url(params = {})
57
+ 'http://cal.syoboi.jp/json.php?Req=ProgramByPID' + Syobocal::Util.format_params_amp(params)
58
+ end
59
+
60
+ def parse(json)
61
+ ::JSON.load(json)
62
+ end
63
+
64
+ module_function :get, :url, :parse
65
+ end
66
+
67
+ module ProgramByCount
68
+ def get(params = {})
69
+ parse(open(url(params)))
70
+ end
71
+
72
+ def url(params = {})
73
+ 'http://cal.syoboi.jp/json.php?Req=ProgramByCount' + Syobocal::Util.format_params_amp(params)
74
+ end
75
+
76
+ def parse(json)
77
+ ::JSON.load(json)
78
+ end
79
+
80
+ module_function :get, :url, :parse
81
+ end
82
+
83
+ module ProgramByDate
84
+ def get(params = {})
85
+ parse(open(url(params)))
86
+ end
87
+
88
+ def url(params = {})
89
+ 'http://cal.syoboi.jp/json.php?Req=ProgramByData' + Syobocal::Util.format_params_amp(params)
90
+ end
91
+
92
+ def parse(json)
93
+ ::JSON.load(json)
94
+ end
95
+
96
+ module_function :get, :url, :parse
97
+ end
98
+
99
+ module SubTitles
100
+ def get(params = {})
101
+ parse(open(url(params)))
102
+ end
103
+
104
+ def url(params = {})
105
+ 'http://cal.syoboi.jp/json.php?Req=SubTitles' + Syobocal::Util.format_params_amp(params)
106
+ end
107
+
108
+ def parse(json)
109
+ ::JSON.load(json)
110
+ end
111
+
112
+ module_function :get, :url, :parse
113
+ end
114
+
115
+ module ChFilter
116
+ def get(params = {})
117
+ parse(open(url(params)))
118
+ end
119
+
120
+ def url(params = {})
121
+ 'http://cal.syoboi.jp/json.php?Req=ChFilter' + Syobocal::Util.format_params_amp(params)
122
+ end
123
+
124
+ def parse(json)
125
+ ::JSON.load(json)
126
+ end
127
+
128
+ module_function :get, :url, :parse
129
+ end
130
+
131
+ module ChIDFilter
132
+ def get(params = {})
133
+ parse(open(url(params)))
134
+ end
135
+
136
+ def url(params = {})
137
+ 'http://cal.syoboi.jp/json.php?Req=ChIDFilter' + Syobocal::Util.format_params_amp(params)
138
+ end
139
+
140
+ def parse(json)
141
+ ::JSON.load(json)
142
+ end
143
+
144
+ module_function :get, :url, :parse
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,51 @@
1
+ module Syobocal
2
+ module RSS
3
+ def get(params = {})
4
+ parse(open(url(params)))
5
+ end
6
+
7
+ def url(params = {})
8
+ 'http://cal.syoboi.jp/rss.php' + Syobocal::Util.format_params(params)
9
+ end
10
+
11
+ def parse(rss)
12
+ rss = REXML::Document.new(rss)
13
+
14
+ result = Result.new
15
+
16
+ channel = rss.elements['rdf:RDF/channel']
17
+ result.title = channel.elements['title'].text
18
+ result.link = channel.elements['link'].text
19
+ result.description = channel.elements['description'].text
20
+
21
+ rss.elements.each('rdf:RDF/item'){|item|
22
+ tv = item.elements['tv:feed']
23
+ result << {
24
+ :about => item.attribute("rdf:about").to_s,
25
+ :title => item.elements['title'].text,
26
+ :link => item.elements['link'].text,
27
+ :description => item.elements['description'].text,
28
+ :dc_date => Time.parse(item.elements['dc:date'].text),
29
+ :dc_publisher => item.elements['dc:publisher'].text,
30
+ :tv_genre => tv.elements['tv:genre'].text,
31
+ :tv_start_datetime => Time.parse(tv.elements['tv:startDatetime'].text),
32
+ :tv_end_datetime => Time.parse(tv.elements['tv:endDatetime'].text),
33
+ :tv_iepg_url => tv.elements['tv:iepgUrl'].text,
34
+ :tv_performer => tv.elements['tv:performer'].text,
35
+ }
36
+ }
37
+
38
+ result
39
+ end
40
+
41
+ module_function :get, :url, :parse
42
+
43
+ class Result < DelegateClass(Array)
44
+ attr_accessor :title, :link, :description
45
+
46
+ def initialize
47
+ super([])
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ module Syobocal
2
+ module RSS2
3
+ def get(params = {})
4
+ parse(open(url(params)))
5
+ end
6
+
7
+ def url(params = {})
8
+ 'http://cal.syoboi.jp/rss2.php' + Syobocal::Util.format_params(params)
9
+ end
10
+
11
+ def parse(rss)
12
+ rss = REXML::Document.new(rss)
13
+
14
+ result = Result.new
15
+
16
+ channel = rss.elements['rss/channel']
17
+ result.title = channel.elements['title'].text
18
+ result.link = channel.elements['link'].text
19
+ result.dc_language = channel.elements['dc:language'].text
20
+ result.pub_date = Time.parse(channel.elements['pubDate'].text)
21
+
22
+ rss.elements.each('rss/channel/item'){|item|
23
+ result << {
24
+ :title => item.elements['title'].text,
25
+ :link => item.elements['link'].text,
26
+ :description => item.elements['description'].text,
27
+ :pub_date => Time.parse(item.elements['pubDate'].text),
28
+ }
29
+ }
30
+
31
+ result
32
+ end
33
+
34
+ module_function :get, :url, :parse
35
+
36
+ class Result < DelegateClass(Array)
37
+ attr_accessor :title, :link, :dc_language, :pub_date
38
+
39
+ def initialize
40
+ super([])
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ module Syobocal
2
+ module Util
3
+ def self.format_params(params)
4
+ return "" if params.length == 0
5
+
6
+ '?' + params.to_a.map{|tuple|
7
+ tuple[0].to_s + '=' + tuple[1].to_s
8
+ }.join('&')
9
+ end
10
+
11
+ def self.format_params_amp(params)
12
+ return "" if params.length == 0
13
+
14
+ "&" + params.to_a.map{|tuple|
15
+ tuple[0].to_s + '=' + tuple[1].to_s
16
+ }.join('&')
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syobocal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - xmisao
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Simple gem for Syoboi Calendar
15
+ email: mail@xmisao.com
16
+ executables:
17
+ - anime
18
+ - syobocal
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/syobocal.rb
23
+ - lib/syobocal/rss2.rb
24
+ - lib/syobocal/rss.rb
25
+ - lib/syobocal/calchk.rb
26
+ - lib/syobocal/json.rb
27
+ - lib/syobocal/util.rb
28
+ - lib/syobocal/db.rb
29
+ - bin/anime
30
+ - bin/syobocal
31
+ homepage: https://github.com/xmisao/syobocal
32
+ licenses:
33
+ - MIT
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.23
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Simple gem for Syoboi Calendar
56
+ test_files: []