Skip to content

Commit e0b2fab

Browse files
committed
Add plugins CHAN-TORU
1 parent 34b9742 commit e0b2fab

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

plugins/subscription/chan_toru.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
# Name:: Automatic::Plugin::Subscription::ChanToru
3+
# Author:: soramugi <http://soramugi.net>
4+
# Created:: Jun 28, 2013
5+
# Updated:: Jun 28, 2013
6+
# Copyright:: Copyright (c) 2013 Automatic Ruby Developers.
7+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
8+
9+
require File.expand_path(File.dirname(__FILE__) + '/g_guide')
10+
11+
module Automatic::Plugin
12+
class SubscriptionChanToru
13+
14+
def initialize(config, pipeline=[])
15+
@config = config
16+
@pipeline = pipeline
17+
end
18+
19+
def g_guide_pipeline
20+
SubscriptionGGuide.new(@config, @pipeline).run
21+
end
22+
23+
def run
24+
retries = 0
25+
begin
26+
pipeline = g_guide_pipeline
27+
pipeline.each {|feeds|
28+
feeds.items.each {|feed|
29+
feed = link_change(feed)
30+
}
31+
}
32+
@pipeline = pipeline
33+
rescue
34+
retries += 1
35+
Automatic::Log.puts("error", "ErrorCount: #{retries}, Fault in parsing: #{retries}")
36+
sleep @config['interval'].to_i unless @config['interval'].nil?
37+
retry if retries <= @config['retry'].to_i unless @config['retry'].nil?
38+
end
39+
40+
@pipeline
41+
end
42+
43+
def link_change(feed)
44+
feed.link.gsub(/([0-9]+)/) do |pid|
45+
if pid != ''
46+
feed.link = "https://tv.so-net.ne.jp/chan-toru/intent" +
47+
"?cat=1&area=23&pid=#{pid}&from=tw"
48+
else
49+
feed.link = nil
50+
end
51+
end
52+
feed
53+
end
54+
55+
end
56+
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -*- coding: utf-8 -*-
2+
# Name:: Automatic::Plugin::Subscription::g_guide
3+
# Author:: soramugi <http://soramugi.net>
4+
# Created:: May 21, 2013
5+
# Updated:: May 21, 2013
6+
# Copyright:: Copyright (c) 2012-2013 Automatic Ruby Developers.
7+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
8+
9+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
10+
11+
require 'subscription/chan_toru'
12+
13+
def chan_toru(config = {}, pipeline = [])
14+
Automatic::Plugin::SubscriptionChanToru.new(config,pipeline)
15+
end
16+
17+
describe 'Automatic::Plugin::SubscriptionChanToru' do
18+
context 'when feed is empty' do
19+
20+
describe 'attestation error' do
21+
subject { chan_toru }
22+
before do
23+
subject.should_receive(:g_guide_pipeline).times.and_return([])
24+
end
25+
its(:run) { should be_empty }
26+
end
27+
28+
describe 'interval & retry was used error' do
29+
config = {'interval' => 1, 'retry' => 1}
30+
subject { chan_toru(config) }
31+
before do
32+
subject.
33+
should_receive(:g_guide_pipeline).
34+
exactly(2).
35+
times.and_return('')
36+
end
37+
its(:run) { should be_empty }
38+
end
39+
40+
end
41+
42+
context 'when feed' do
43+
describe 'config keyword' do
44+
subject { chan_toru }
45+
before do
46+
pipeline = AutomaticSpec.generate_pipeline {
47+
feed {
48+
item "http://soramugi.net/images/hugehuge"
49+
item "http://tv.so-net.ne.jp/schedule/500333201307052330.action?from=rss"
50+
}}
51+
subject.
52+
should_receive(:g_guide_pipeline).
53+
times.and_return(pipeline)
54+
end
55+
its(:run) { should have(1).feed }
56+
end
57+
58+
end
59+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
global:
2+
timezone: Asia/Tokyo
3+
cache:
4+
base: /tmp
5+
log:
6+
level: none
7+
8+
plugins:
9+
- module: SubscriptionChanToru
10+
config:
11+
keyword: 'アニメ'
12+
station: '地上波'
13+
14+
- module: StorePermalink
15+
config:
16+
db: test_chan_toru.db
17+
18+
#- module: PublishConsoleLink

0 commit comments

Comments
 (0)