ellen-syoboi_calendar 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +3 -0
- data/images/screenshot.gif +0 -0
- data/lib/ellen/handlers/syoboi_calendar.rb +48 -22
- data/lib/ellen/syoboi_calendar/program.rb +22 -0
- data/lib/ellen/syoboi_calendar/record.rb +29 -0
- data/lib/ellen/syoboi_calendar/title.rb +12 -0
- data/lib/ellen/syoboi_calendar/version.rb +1 -1
- data/lib/ellen/syoboi_calendar.rb +3 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5407684549c70fbee83244ff539c04a37c962ee
|
4
|
+
data.tar.gz: 0bdc13a03589da35e52cfa63811a6090d41bdbd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 329582c7428aab4ee2b49ccf0540599f7bfc7b2ef89aea7aeb3bcbfaa4ad4826c0731ee966d76315e0598ac44c36890c46ffa141a37a83a13a8f1e04ec06a1e5
|
7
|
+
data.tar.gz: 8955e82270eca0749206c7d89cf9d5878e8871c3931e86fd99a249732227f3f6343f04967ca6fd5a353bc2a004351648d6f070f0495fa550220ef0fda4033ee8
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
Binary file
|
@@ -1,4 +1,6 @@
|
|
1
|
+
require "active_support/core_ext/enumerable"
|
1
2
|
require "active_support/core_ext/numeric/time"
|
3
|
+
require "active_support/core_ext/date"
|
2
4
|
require "active_support/core_ext/time"
|
3
5
|
|
4
6
|
module Ellen
|
@@ -6,15 +8,25 @@ module Ellen
|
|
6
8
|
class SyoboiCalendar < Base
|
7
9
|
on(/list anime\z/, name: "list", description: "List today's anime")
|
8
10
|
|
11
|
+
env :SYOBOI_CALENDAR_CHANNEL_IDS, "Comma-separated channel IDs to filter programs", optional: true
|
12
|
+
|
9
13
|
def list(message)
|
10
|
-
message.reply(
|
14
|
+
message.reply(description)
|
11
15
|
end
|
12
16
|
|
13
17
|
private
|
14
18
|
|
19
|
+
def description
|
20
|
+
if descriptions.empty?
|
21
|
+
"No programs found"
|
22
|
+
else
|
23
|
+
descriptions.join("\n")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
15
27
|
def descriptions
|
16
|
-
programs_sorted_by_started_at.map do |program|
|
17
|
-
"#{program
|
28
|
+
@descriptions ||= programs_sorted_by_started_at.map do |program|
|
29
|
+
"#{program.started_at_in_string} #{titles_index_by_id[program.title_id].title} #{program.count}"
|
18
30
|
end
|
19
31
|
end
|
20
32
|
|
@@ -22,19 +34,17 @@ module Ellen
|
|
22
34
|
@client ||= ::SyoboiCalendar::Client.new
|
23
35
|
end
|
24
36
|
|
25
|
-
def
|
26
|
-
@titles_by_id ||= titles.
|
27
|
-
table.merge(title[:id] => title)
|
28
|
-
end
|
37
|
+
def titles_index_by_id
|
38
|
+
@titles_by_id ||= titles.index_by(&:id)
|
29
39
|
end
|
30
40
|
|
31
41
|
def titles
|
32
42
|
[get_titles.TitleLookupResponse.TitleItems.TitleItem].flatten.map do |title|
|
33
|
-
|
43
|
+
Ellen::SyoboiCalendar::Title.new(
|
34
44
|
id: title.id,
|
35
45
|
title: title.Title,
|
36
46
|
short_title: title.ShortTitle,
|
37
|
-
|
47
|
+
)
|
38
48
|
end
|
39
49
|
end
|
40
50
|
|
@@ -50,46 +60,62 @@ module Ellen
|
|
50
60
|
|
51
61
|
def title_ids_in_programs
|
52
62
|
programs.map do |program|
|
53
|
-
program
|
63
|
+
program.title_id
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
57
67
|
def programs_sorted_by_started_at
|
58
|
-
programs.sort_by
|
59
|
-
program[:started_at]
|
60
|
-
end
|
68
|
+
programs.sort_by(&:started_at)
|
61
69
|
end
|
62
70
|
|
63
71
|
def programs
|
64
|
-
@programs ||=
|
65
|
-
|
72
|
+
@programs ||= get_programs.map do |program|
|
73
|
+
Ellen::SyoboiCalendar::Program.new(
|
66
74
|
count: program.Count,
|
67
75
|
channel_id: program.ChID,
|
68
76
|
sub_title: program.STSubTitle,
|
69
77
|
title_id: program.TID,
|
70
|
-
started_at:
|
71
|
-
finished_at:
|
72
|
-
|
78
|
+
started_at: program.StTime,
|
79
|
+
finished_at: program.EdTime,
|
80
|
+
)
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
76
84
|
def get_programs
|
77
|
-
client.programs(program_options)
|
85
|
+
if items = client.programs(program_options).ProgLookupResponse.ProgItems
|
86
|
+
[items.ProgItem].flatten.compact
|
87
|
+
else
|
88
|
+
[]
|
89
|
+
end
|
78
90
|
end
|
79
91
|
|
80
92
|
def program_options
|
81
93
|
{
|
82
94
|
played_from: played_from,
|
83
95
|
played_to: played_to,
|
84
|
-
|
96
|
+
channel_id: channel_ids,
|
97
|
+
}.reject {|key, value| value.nil? }
|
98
|
+
end
|
99
|
+
|
100
|
+
def channel_ids
|
101
|
+
ENV["SYOBOI_CALENDAR_CHANNEL_IDS"]
|
102
|
+
end
|
103
|
+
|
104
|
+
def now
|
105
|
+
@now ||= Time.now
|
85
106
|
end
|
86
107
|
|
87
108
|
def played_from
|
88
|
-
|
109
|
+
now
|
89
110
|
end
|
90
111
|
|
112
|
+
# 04:00 ~ 28:00
|
91
113
|
def played_to
|
92
|
-
|
114
|
+
if now.hour >= 4
|
115
|
+
now.tomorrow.beginning_of_day + 4.hour
|
116
|
+
else
|
117
|
+
now.beginning_of_day + 4.hour
|
118
|
+
end
|
93
119
|
end
|
94
120
|
end
|
95
121
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ellen
|
2
|
+
module SyoboiCalendar
|
3
|
+
class Program < Record
|
4
|
+
|
5
|
+
property(
|
6
|
+
:channel_id,
|
7
|
+
:count,
|
8
|
+
:sub_title,
|
9
|
+
:title_id,
|
10
|
+
)
|
11
|
+
|
12
|
+
time_property(
|
13
|
+
:finished_at,
|
14
|
+
:started_at,
|
15
|
+
)
|
16
|
+
|
17
|
+
def started_at_in_string
|
18
|
+
started_at.strftime("%Y-%m-%d %H:%M")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Ellen
|
2
|
+
module SyoboiCalendar
|
3
|
+
class Record
|
4
|
+
class << self
|
5
|
+
def property(*names)
|
6
|
+
names.each do |name|
|
7
|
+
define_method(name) do
|
8
|
+
properties[name]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def time_property(*names)
|
14
|
+
names.each do |name|
|
15
|
+
define_method(name) do
|
16
|
+
Time.parse(properties[name])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :properties
|
23
|
+
|
24
|
+
def initialize(properties)
|
25
|
+
@properties = properties
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ellen-syoboi_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -144,13 +144,18 @@ extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
146
|
- ".gitignore"
|
147
|
+
- CHANGELOG.md
|
147
148
|
- Gemfile
|
148
149
|
- LICENSE.txt
|
149
150
|
- README.md
|
150
151
|
- Rakefile
|
151
152
|
- ellen-syoboi_calendar.gemspec
|
153
|
+
- images/screenshot.gif
|
152
154
|
- lib/ellen/handlers/syoboi_calendar.rb
|
153
155
|
- lib/ellen/syoboi_calendar.rb
|
156
|
+
- lib/ellen/syoboi_calendar/program.rb
|
157
|
+
- lib/ellen/syoboi_calendar/record.rb
|
158
|
+
- lib/ellen/syoboi_calendar/title.rb
|
154
159
|
- lib/ellen/syoboi_calendar/version.rb
|
155
160
|
- spec/ellen/handlers/syoboi_calendar_spec.rb
|
156
161
|
- spec/spec_helper.rb
|