imas-producer_schedule 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 597b3bce2b01ca8c9e8abe5e4ab0754f3824350b
4
+ data.tar.gz: 45ecbf3ad07d251ebda0eb9b143638fa788dcd1f
5
+ SHA512:
6
+ metadata.gz: a60b255eb96c9b85451bcc814eae1e931869b8f0931b686c2278535822e8fc0f7bfa96f297b37eb57505bc852227e007b60b583bea1a282770270052bc433551
7
+ data.tar.gz: 22371b0245a1eb826eb5248fa2f7676870800f009198d5f40c068cf0bde4e25aae103a25b5500a802522703562cff3252edf00253bdefe9dc9cc07cdfb4e5cfd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imas-producer_schedule.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 gomao9
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Imas::ProducerSchedule
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/imas/producer_schedule`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'imas-producer_schedule'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install imas-producer_schedule
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/imas-producer_schedule.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "imas/producer_schedule"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "pry"
14
+ pry
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/p_cal ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'imas/producer_schedule'
4
+ c = Imas::ProducerSchedule::Client.new
5
+ c.output_cal(ARGV.first || '.')
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'imas/producer_schedule/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "imas-producer_schedule"
8
+ spec.version = Imas::ProducerSchedule::VERSION
9
+ spec.authors = ["gomao9"]
10
+ spec.email = ["gomaoq@gmail.com"]
11
+
12
+ spec.summary = "calendar generator for im@s producers"
13
+ spec.homepage = "http://github.com/hsugita/imas-producer_schedule"
14
+ spec.license = "MIT"
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
20
+ end
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.12"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_dependency 'icalendar'
32
+ spec.add_dependency 'nokogiri', '~> 1.6.5'
33
+ spec.add_dependency 'activesupport'
34
+ end
@@ -0,0 +1,196 @@
1
+ require 'open-uri'
2
+ require 'icalendar'
3
+ require 'nokogiri'
4
+ require 'yaml'
5
+ require 'active_support'
6
+
7
+ module Imas::ProducerSchedule
8
+ class Client
9
+ REGULAR_ARTICLE = [
10
+ /^デレラジ$/,
11
+ /^THE IDOLM@STER STATION!!\+$/,
12
+ /^ラジオdeアイマchu!!$/,
13
+ /^アイマスタジオ$/,
14
+ /^【CINDERELLA Night】デレラジA$/,
15
+ /^CINDERELLA PARTY!$/,
16
+ /^THE IDOLM@STER STATION!!!$/,
17
+ /^ミリオンラジオ!$/,
18
+ /^アイドルマスター シンデレラガールズ .{1,2}話放送$/,
19
+ /^アイドルマスター シンデレラガールズ .{1,2}話配信(バンダイチャンネル)$/,
20
+ /^【CINDERELLA Night】アイドルマスター シンデレラガールズ .{1,2}話配信(ニコ生)$/,
21
+ /^「リスアニ!TV」TVAシンデレラガールズコーナー$/,
22
+ /^315プロNight!$/,
23
+ /^アイドルマスター .{1,2}話放送(再放送)$/,
24
+ /^アイドルマスター シンデレラガールズ .{1,2}話放送(再放送)$/,
25
+ /^デレラジ☆(スター)$/,
26
+ ]
27
+ HEADER_OFFSET = 3
28
+ TZID = 'Asia/Tokyo'
29
+ DEFAULT_MONTH_PATH = File.join(File.expand_path('../../../../', __FILE__), 'months.yml')
30
+
31
+
32
+ def initialize(month_path = DEFAULT_MONTH_PATH)
33
+ @months = ::YAML.load_file(month_path)
34
+ end
35
+
36
+ def output_cal(output_dir = '.')
37
+ # カレンダー情報定義
38
+ cals = [
39
+ { name:"プロデューサー予定表",
40
+ file:"schedule.ics",
41
+ test: lambda{|schedule| true },
42
+ },
43
+ { name:"定期配信番組除外版",
44
+ file:"schedule_irregular.ics",
45
+ test: lambda{|schedule| REGULAR_ARTICLE.none? {|re| schedule[:article] =~ re} },
46
+ },
47
+ { name:"定期配信番組のみ",
48
+ file:"schedule_regular.ics",
49
+ test: lambda{|schedule| REGULAR_ARTICLE.any? {|re| schedule[:article] =~ re} },
50
+ },
51
+ { name:"発売日",
52
+ file:"release_day.ics",
53
+ test: lambda{|schedule| schedule[:time] == "発売日"}
54
+ },
55
+ { name:"イベント" ,
56
+ file:"event.ics",
57
+ test: lambda{|schedule| schedule[:genre].include? "イベント"}
58
+ },
59
+ { name:"ニコ生" ,
60
+ file:"nico_live.ics",
61
+ test: lambda{|schedule| schedule[:genre].include? "ニコ生"}
62
+ },
63
+ ]
64
+
65
+ # タイトル・タイムゾーン設定
66
+ cals.each do |cal|
67
+ calendar = Icalendar::Calendar.new
68
+ calendar.append_custom_property('X-WR-CALNAME;VALUE=TEXT', cal[:name])
69
+ set_timezone calendar
70
+ cal[:cal] = calendar
71
+ end
72
+
73
+ @months.each do |year, str, num, type|
74
+ url = case type
75
+ when 'a' then "http://idolmaster.jp/schedule/#{year}#{str}.php"
76
+ when 'b' then "http://idolmaster.jp/schedule/#{year}/#{str}.php"
77
+ when 'c' then "http://idolmaster.jp/schedule/?ey=#{year}&em=#{str}"
78
+ end
79
+ schedules = parse_calendar url
80
+ month = num
81
+
82
+ # イベント設定
83
+ day = nil # いらないかも?
84
+ schedules.each do |s|
85
+ e = Icalendar::Event.new
86
+
87
+ # s[:day]がnilならば直前の日付と同じ
88
+ day = s[:day] || day
89
+
90
+ # 日付時刻
91
+ if s[:from].nil?
92
+ e.dtstart = Icalendar::Values::Date.new(sprintf("%04d%02d%02d", year, month, day), 'tzid' => TZID)
93
+ else
94
+ st_tm = to_datetime(year, month, day, *split_time(s[:from]))
95
+ ed_tm = st_tm
96
+ unless s[:to].nil?
97
+ ed_tm = to_datetime(year, month, day, *split_time(s[:to]))
98
+ end
99
+ e.dtstart = st_tm
100
+ e.dtend = ed_tm
101
+ end
102
+
103
+ # ジャンル
104
+ e.append_custom_property('X-GENRE;VALUE=TEXT', s[:genre])
105
+ # リンク
106
+ e.append_custom_property('X-LINK;VALUE=TEXT', s[:link]) if s[:link]
107
+ # 時間
108
+ e.append_custom_property('X-TIME;VALUE=TEXT', s[:time])
109
+
110
+ # サマリ
111
+ e.summary = s[:article]
112
+ # 詳細
113
+ e.description = s[:description]
114
+
115
+ # カレンダーへ追加
116
+ cals.each do |c|
117
+ c[:cal].add_event e if c[:test].call(s)
118
+ end
119
+
120
+ end
121
+ end
122
+
123
+ # カレンダー発行
124
+ cals.each do |c|
125
+ c[:cal].publish
126
+ open(File.join(output_dir, c[:file]), 'w') { |f| f.write(c[:cal].to_ical) }
127
+ end
128
+
129
+ end
130
+
131
+ private
132
+
133
+ def to_schedule tr
134
+ # ジャンル
135
+ genre = tr.at('.//td[@class="genre2"]').try(:text)
136
+ # 内容・リンク
137
+ article = tr.at('.//td[@class="article2"]').try(:text)
138
+ link = tr.at('.//td[@class="article2"]/a').try(:[], 'href')
139
+ # 日付
140
+ day = tr.at('.//td[@class="day2"]/img')
141
+ day = tr.at('.//td[@class="day"]/img') unless day
142
+ day = day['src'][-6..-5].to_i if day
143
+ # 時刻
144
+ time = tr.at('.//td[@class="time2"]').try(:text)
145
+ # From-To
146
+ from, to = time.try(:tr, '1234567890:', '1234567890:').try(:scan, /\d\d:\d\d/)
147
+ # 出演者
148
+ performance = tr.at('.//td[@class="performance2"]/img').try(:[], 'alt')
149
+ # 詳細
150
+ description = "時間:#{time}\n"
151
+ description << "出演:#{performance}\n"
152
+ description << "記事:#{article}\n"
153
+ description << "リンク:#{link}\n"
154
+
155
+ # ハッシュ生成
156
+ {day:day, time:time, genre:genre.try(:strip), article:article, link:link, from:from, to:to, description:description} unless article.blank?
157
+ end
158
+
159
+ def parse_calendar url
160
+ html = open(url) { |f| f.read }
161
+ charset = 'utf-8'
162
+
163
+ # htmlをパースしてオブジェクトを生成
164
+ doc = Nokogiri::HTML.parse(html, nil, charset)
165
+ doc.xpath('//*[@id="tabelarea"]/table/tr').drop(HEADER_OFFSET).map do |tr|
166
+ to_schedule(tr)
167
+ end.compact
168
+ end
169
+
170
+ def to_datetime year, month, day, hour, min
171
+ if hour >= 24
172
+ hour -= 24
173
+ exceed = true
174
+ end
175
+ datetime = DateTime.civil(year, month, day, hour, min)
176
+ datetime += 1.day if exceed
177
+ Icalendar::Values::DateTime.new datetime, 'tzid' => TZID
178
+ end
179
+
180
+ def split_time hm_string
181
+ hm_string.split(':').map(&:to_i)
182
+ end
183
+
184
+ def set_timezone cal
185
+ cal.timezone do |t|
186
+ t.tzid = TZID
187
+ t.standard do |s|
188
+ s.tzoffsetfrom = '+0900'
189
+ s.tzoffsetto = '+0900'
190
+ s.tzname = 'JST'
191
+ s.dtstart = '19700101T000000'
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,5 @@
1
+ module Imas
2
+ module ProducerSchedule
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "imas/producer_schedule/version"
2
+ require 'imas/producer_schedule/client'
3
+
4
+ module Imas
5
+ module ProducerSchedule
6
+ end
7
+ end
data/months.yml ADDED
@@ -0,0 +1,28 @@
1
+ ---
2
+ - [2014, 'july', 7, 'a']
3
+ - [2014, 'august', 8, 'a']
4
+ - [2014, 'september', 9, 'a']
5
+ - [2014, 'october', 10, 'a']
6
+ - [2014, 'november', 11, 'a']
7
+ - [2014, 'december', 12, 'a']
8
+ - [2015, 'january', 1, 'a']
9
+ - [2015, 'february', 2, 'a']
10
+ - [2015, 'march', 3, 'a']
11
+ - [2015, 'april', 4, 'a']
12
+ - [2015, 'may', 5, 'a']
13
+ - [2015, 'june', 6, 'a']
14
+ - [2015, 'july', 7, 'a']
15
+ - [2015, 'august', 8, 'a']
16
+ - [2015, 'september', 9, 'a']
17
+ - [2015, 'october', 10, 'a']
18
+ - [2015, 'november', 11, 'a']
19
+ - [2015, 'december', 12, 'a']
20
+ - [2016, 'january', 1, 'b']
21
+ - [2016, 'february', 2, 'b']
22
+ - [2016, 'march', 3, 'b']
23
+ - [2016, 'april', 4, 'b']
24
+ - [2016, 'may', 5, 'b']
25
+ - [2016, 'june', 6, 'b']
26
+ - [2016, '07', 7, 'c']
27
+ - [2016, '08', 8, 'c']
28
+ - [2016, '09', 9, 'c']
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imas-producer_schedule
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - gomao9
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: icalendar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.5
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.5
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - gomaoq@gmail.com
114
+ executables:
115
+ - p_cal
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - exe/p_cal
127
+ - imas-producer_schedule.gemspec
128
+ - lib/imas/producer_schedule.rb
129
+ - lib/imas/producer_schedule/client.rb
130
+ - lib/imas/producer_schedule/version.rb
131
+ - months.yml
132
+ homepage: http://github.com/hsugita/imas-producer_schedule
133
+ licenses:
134
+ - MIT
135
+ metadata:
136
+ allowed_push_host: https://rubygems.org
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.6.6
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: calendar generator for im@s producers
157
+ test_files: []