mitten 0.0.5 → 0.0.6
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/.gitignore +5 -24
- data/Gemfile +4 -0
- data/LICENSE +5 -4
- data/README.markdown +53 -0
- data/Rakefile +19 -45
- data/VERSION +1 -1
- data/bin/mitten +7 -0
- data/configs/example_environment.yaml +6 -5
- data/example/{sample.rb → echo.rb} +8 -2
- data/lib/mitten.rb +7 -9
- data/lib/{plugin.rb → mitten/plugin.rb} +9 -4
- data/lib/{utils.rb → mitten/utils.rb} +3 -2
- data/lib/mitten/version.rb +3 -0
- data/mitten.gemspec +16 -92
- metadata +58 -151
- data/.document +0 -5
- data/README.rdoc +0 -81
- data/bin/client +0 -10
- data/bin/daemon +0 -8
- data/configs/time_call.yaml +0 -13
- data/configs/twitter_bot.yaml +0 -3
- data/plugins/amazon_search.rb +0 -62
- data/plugins/bmi.rb +0 -48
- data/plugins/codepad.rb +0 -63
- data/plugins/fortune.rb +0 -40
- data/plugins/gasoline.rb +0 -46
- data/plugins/gmail.rb +0 -64
- data/plugins/google_profile.rb +0 -37
- data/plugins/google_transit.rb +0 -56
- data/plugins/google_weather.rb +0 -34
- data/plugins/holoscope.rb +0 -63
- data/plugins/loo_holoscope.rb +0 -51
- data/plugins/mixi_voice.rb +0 -139
- data/plugins/nanapi.rb +0 -31
- data/plugins/newspaper_headlines.rb +0 -48
- data/plugins/openpne_new_diary_check.rb +0 -66
- data/plugins/ramen.rb +0 -33
- data/plugins/rate.rb +0 -31
- data/plugins/screen_time_search.rb +0 -96
- data/plugins/time_call.rb +0 -25
- data/plugins/tweet.rb +0 -32
- data/plugins/twitter_bot.rb +0 -32
- data/plugins/typhoon.rb +0 -37
- data/plugins/uri_shorten.rb +0 -23
- data/spec/mitten_spec.rb +0 -11
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -9
data/plugins/mixi_voice.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'mechanize'
|
3
|
-
require 'nokogiri'
|
4
|
-
|
5
|
-
=begin
|
6
|
-
|
7
|
-
ex. environment.yaml
|
8
|
-
|
9
|
-
MixiVoice:
|
10
|
-
sleep: 60
|
11
|
-
channel: '#Mitten@freenode'
|
12
|
-
email: 'email'
|
13
|
-
password: 'password'
|
14
|
-
|
15
|
-
=end
|
16
|
-
class MixiVoice < Mitten::Plugin
|
17
|
-
MIXI_LOGIN_URI = 'http://mixi.jp'
|
18
|
-
RECENT_VOICE_URI = MIXI_LOGIN_URI + '/recent_echo.pl'
|
19
|
-
|
20
|
-
def initialize(*args)
|
21
|
-
super
|
22
|
-
|
23
|
-
@email = @config['email']
|
24
|
-
@password = @config['password']
|
25
|
-
@nickname = @config['nickname']
|
26
|
-
|
27
|
-
@agent = Mechanize.new
|
28
|
-
if ENV['http_proxy']
|
29
|
-
proxy = URI.parse(ENV['http_proxy'])
|
30
|
-
@agent.set_proxy(proxy.host, proxy.port)
|
31
|
-
end
|
32
|
-
|
33
|
-
@caches = []
|
34
|
-
end
|
35
|
-
|
36
|
-
def before_hook
|
37
|
-
login
|
38
|
-
@identity = get_identity
|
39
|
-
end
|
40
|
-
|
41
|
-
def login
|
42
|
-
@agent.get MIXI_LOGIN_URI do |login_page|
|
43
|
-
login_page.form 'login_form' do |form|
|
44
|
-
form.email = @email
|
45
|
-
form.password = @password
|
46
|
-
end.submit
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def on_privmsg(prefix, channel, message)
|
51
|
-
if prefix =~ Regexp.new(@nickname)
|
52
|
-
case message
|
53
|
-
when /^re ([0-9]+) (.+)/
|
54
|
-
reply(channel, $1, $2)
|
55
|
-
when /^rm ([0-9]+)/
|
56
|
-
delete($1)
|
57
|
-
when /^add (.+)/
|
58
|
-
add($1)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def main
|
64
|
-
get
|
65
|
-
end
|
66
|
-
|
67
|
-
def get
|
68
|
-
voices = crawl_recent_voice
|
69
|
-
voices.sort.each do |key, voice|
|
70
|
-
if @caches.empty? or !@caches.has_key? key
|
71
|
-
@channels.each do |channel|
|
72
|
-
notice(channel, "mixi voice: [#{voice[:nickname]}]#{voice[:reply]} #{voice[:comment]} (#{key})")
|
73
|
-
sleep 5
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
@caches = voices
|
78
|
-
end
|
79
|
-
|
80
|
-
def get_identity
|
81
|
-
recent_page = @agent.get RECENT_VOICE_URI
|
82
|
-
identity = (Nokogiri::HTML(recent_page.body)/'input#post_key').first['value']
|
83
|
-
end
|
84
|
-
|
85
|
-
def reply(channel, key, voice)
|
86
|
-
if @caches.has_key? key
|
87
|
-
member_id = @caches[key][:member_id]
|
88
|
-
post_time = @caches[key][:post_time]
|
89
|
-
|
90
|
-
@agent.get RECENT_VOICE_URI do |post_page|
|
91
|
-
post_page.form_with(:action => '/add_echo.pl') do |form|
|
92
|
-
form.body = voice
|
93
|
-
form.parent_member_id = member_id
|
94
|
-
form.parent_post_time = post_time
|
95
|
-
end.submit
|
96
|
-
end
|
97
|
-
else
|
98
|
-
notice(channel, '指定された返信先が見つかりません')
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def delete(post_time)
|
103
|
-
@agent.post "http://mixi.jp/delete_echo.pl?post_time=#{post_time}&post_key=#{@identity}&redirect=recent_echo"
|
104
|
-
@caches = crawl_recent_voice
|
105
|
-
end
|
106
|
-
|
107
|
-
def add(voice)
|
108
|
-
@agent.get RECENT_VOICE_URI do |post_page|
|
109
|
-
post_page.form_with(:action => 'add_echo.pl') do |form|
|
110
|
-
form.body = voice
|
111
|
-
end.submit
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def crawl_recent_voice
|
116
|
-
recent_page = @agent.get RECENT_VOICE_URI
|
117
|
-
voices = {}
|
118
|
-
|
119
|
-
(Nokogiri::HTML(recent_page.body)/'td.comment').each do |comment|
|
120
|
-
key = timestamp(comment)
|
121
|
-
voices[key] = build_voice(comment)
|
122
|
-
end
|
123
|
-
voices
|
124
|
-
end
|
125
|
-
|
126
|
-
def timestamp(comment)
|
127
|
-
comment.at('div.echo_post_time').text
|
128
|
-
end
|
129
|
-
|
130
|
-
def build_voice(comment)
|
131
|
-
{
|
132
|
-
:member_id => comment.at('div.echo_member_id').text,
|
133
|
-
:post_time => comment.at('div.echo_post_time').text,
|
134
|
-
:nickname => comment.at('div.echo_nickname').text,
|
135
|
-
:reply => ((' ' + comment.at('a').text) if comment.at('a').text =~ /^>/),
|
136
|
-
:comment => comment.at('div.echo_body').text
|
137
|
-
}
|
138
|
-
end
|
139
|
-
end
|
data/plugins/nanapi.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class Nanapi < Mitten::Plugin
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
@suffix = @config['suffix'] || 'テクニック教えて'
|
8
|
-
end
|
9
|
-
|
10
|
-
def on_privmsg(prefix, channel, message)
|
11
|
-
case message
|
12
|
-
when /^(.+)#{@suffix}$/
|
13
|
-
result = search_technique($1)
|
14
|
-
|
15
|
-
if result == nil
|
16
|
-
notice(channel, '/(^o^)\ わかにゃいっ')
|
17
|
-
else
|
18
|
-
notice(channel, result.to_s)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def search_technique(keyword)
|
26
|
-
doc = Nokogiri::XML(open("http://nanapi.jp/search/keyword:#{URI.encode(keyword)}/feed.rss").read)
|
27
|
-
item = (doc/'item').to_a.choice
|
28
|
-
|
29
|
-
"#{item.at('title').text} - #{URI.short(item.at('link').text)}" if item
|
30
|
-
end
|
31
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'rss'
|
3
|
-
|
4
|
-
class NewspaperHeadlines < Mitten::Plugin
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
|
8
|
-
@publishers = {
|
9
|
-
'琉球新報' => 'http://rss.ryukyushimpo.jp/rss/ryukyushimpo/index.rdf',
|
10
|
-
'沖縄タイムス' => 'http://www.okinawatimes.co.jp/rss/20/index.xml',
|
11
|
-
'読売新聞' => 'http://rss.yomiuri.co.jp/rss/yol/topstories',
|
12
|
-
'毎日新聞' => 'http://mainichi.jp/rss/etc/flash.rss',
|
13
|
-
'日経新聞' => 'http://www.nikkeibp.co.jp/rss/index.rdf',
|
14
|
-
'CNN' => 'http://headlines.yahoo.co.jp/rss/cnn_c_int.xml',
|
15
|
-
'映画ニュース' => 'http://headlines.yahoo.co.jp/rss/cine.xml',
|
16
|
-
'ITMedia' => 'http://headlines.yahoo.co.jp/rss/itmedia_n.xml',
|
17
|
-
'dankogai' => 'http://blog.livedoor.jp/dankogai/index.rdf',
|
18
|
-
'インフルエンザ' => 'http://www3.asahi.com/rss/pandemicflu.rdf'
|
19
|
-
}
|
20
|
-
@limit = @config['limit'] || 3
|
21
|
-
end
|
22
|
-
|
23
|
-
def on_privmsg(prefix, channel, publisher_name)
|
24
|
-
if publisher_name == 'ニュースリスト'
|
25
|
-
notice(channel, @publishers.keys.join(' / '))
|
26
|
-
elsif @publishers.key? publisher_name
|
27
|
-
get_headlines(@publishers[publisher_name]).each do |headline|
|
28
|
-
notice(channel, headline.to_s)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def get_headlines(publisher_uri)
|
36
|
-
rss = RSS::Parser.parse(open(publisher_uri).read, false)
|
37
|
-
rss.items.delete_if { |item| item.title =~ /(AD|PR)/ }
|
38
|
-
|
39
|
-
headlines = [rss.channel.title + ' のニュースだよ!']
|
40
|
-
rss.items[0...@limit].each do |item|
|
41
|
-
title = item.title
|
42
|
-
url = URI.short(item.link)
|
43
|
-
date = item.date.strftime("%d日 %H:%M")
|
44
|
-
headlines << "[#{date}] #{title} (#{url})"
|
45
|
-
end
|
46
|
-
headlines
|
47
|
-
end
|
48
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'sdbm'
|
2
|
-
require 'mechanize'
|
3
|
-
require 'nokogiri'
|
4
|
-
|
5
|
-
=begin
|
6
|
-
|
7
|
-
ex. environment.yaml
|
8
|
-
|
9
|
-
OpenPNENewDiaryCheck:
|
10
|
-
sleep: 60
|
11
|
-
channel: '#Mitten@freenode'
|
12
|
-
uri : 'http://openpne.example.com'
|
13
|
-
username: 'username'
|
14
|
-
password: 'password'
|
15
|
-
|
16
|
-
=end
|
17
|
-
class OpenPNENewDiaryCheck < Mitten::Plugin
|
18
|
-
def initialize(*args)
|
19
|
-
super
|
20
|
-
|
21
|
-
@uri = @config['uri']
|
22
|
-
@username = @config['username']
|
23
|
-
@password = @config['password']
|
24
|
-
end
|
25
|
-
|
26
|
-
def before_hook
|
27
|
-
login
|
28
|
-
end
|
29
|
-
|
30
|
-
def login
|
31
|
-
@agent = Mechanize.new
|
32
|
-
@agent.get(@uri) do |login_page|
|
33
|
-
login_page.form_with(:name => 'login') do |f|
|
34
|
-
f.username = @username
|
35
|
-
f.password = @password
|
36
|
-
end.submit
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def main
|
41
|
-
begin
|
42
|
-
db = SDBM.open("/tmp/openpnenewdiarycheck_#{@username}.db")
|
43
|
-
diary_page = @agent.get "#{@uri}/?m=pc&a=page_h_diary_list_all"
|
44
|
-
diaries = Nokogiri::HTML(diary_page.body)/'div.item'
|
45
|
-
|
46
|
-
diaries[1...diaries.size].each do |diary|
|
47
|
-
uri = "#{@uri}/#{(diary/'td.photo/a').first.attributes['href']}"
|
48
|
-
redo if uri == nil or uri == ''
|
49
|
-
|
50
|
-
unless db.include? uri
|
51
|
-
db[uri] = '1'
|
52
|
-
nick = ((diary/'td').to_a)[1].text.gsub(/ \(.*\)$/, '')
|
53
|
-
title = ((diary/'td').to_a)[2].text.gsub(/ \([0-9].?\)/, '')
|
54
|
-
message = "#{nick}さんが「#{title}」を投稿しました! (#{uri})"
|
55
|
-
|
56
|
-
@channels.each do |channel|
|
57
|
-
notice(channel, message)
|
58
|
-
sleep 5
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
ensure
|
63
|
-
db.close
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/plugins/ramen.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class Ramen < Mitten::Plugin
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
|
8
|
-
@suffix = @config['suffix'] || 'ラーメン食わせろ'
|
9
|
-
@base_uri = 'http://ramen.tedaco.net/'
|
10
|
-
@rank_uri = @base_uri + 'index.php'
|
11
|
-
end
|
12
|
-
|
13
|
-
def on_privmsg(prefix, channel, message)
|
14
|
-
case message
|
15
|
-
when /^#{@suffix}/
|
16
|
-
notice(channel, shop_choice)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def shop_choice
|
21
|
-
begin
|
22
|
-
list = Nokogiri::HTML(open(@rank_uri).read)/'.access_rank'
|
23
|
-
|
24
|
-
shop = list.to_a.choice
|
25
|
-
name = shop.at('a').text
|
26
|
-
detail = URI.short(@base_uri + shop.at('a').attributes['href'])
|
27
|
-
|
28
|
-
"#{name} に行けば? (#{detail})"
|
29
|
-
rescue Exception =>e
|
30
|
-
ranking << 'こわれたっ/(^o^)\'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/plugins/rate.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class Rate < Mitten::Plugin
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
@suffix = @config['suffix'] || '度判定して'
|
8
|
-
end
|
9
|
-
|
10
|
-
def on_privmsg(prefix, channel, message)
|
11
|
-
case message
|
12
|
-
when /^(.+)#{@suffix}$/
|
13
|
-
result = rating($1, prefix.nick)
|
14
|
-
|
15
|
-
if result == nil
|
16
|
-
notice(channel, '/(^o^)\ わかにゃいっ')
|
17
|
-
else
|
18
|
-
notice(channel, result.to_s)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def rating(genre, nick)
|
26
|
-
uri = "http://kistools.appspot.com/r/#{URI.encode(genre)}/#{nick}"
|
27
|
-
doc = Nokogiri::XML(open(uri).read)
|
28
|
-
|
29
|
-
(doc/'table.input_form').first.at('td').text.match(/^(.+)?です。/).to_s.strip + " (#{URI.short(uri)})"
|
30
|
-
end
|
31
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
class ScreenTimeSearch < Mitten::Plugin
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
|
8
|
-
@theaters_uri = [
|
9
|
-
'http://www.startheaters.jp/schedule',
|
10
|
-
'http://www.google.co.jp/movies?tid=3d1a4be489681836'
|
11
|
-
]
|
12
|
-
@movies_uri = 'http://www.startheaters.jp/movie'
|
13
|
-
@pickup_uri = 'http://www.startheaters.jp/'
|
14
|
-
|
15
|
-
@all = @config['all'] || '映画見たい'
|
16
|
-
@suffix = @config['suffix'] || 'の上映時間教えて'
|
17
|
-
@pickup = @config['pickup'] || 'おすすめ映画'
|
18
|
-
end
|
19
|
-
|
20
|
-
def on_privmsg(prefix, channel, message)
|
21
|
-
@results = []
|
22
|
-
|
23
|
-
case message
|
24
|
-
when /^#{@all}(.+|)$/
|
25
|
-
@results << '今やってる映画だよ♪'
|
26
|
-
get_movies_list @movies_uri
|
27
|
-
when /^#{@pickup}(.+|)$/
|
28
|
-
@results << 'おすすめ映画ピックアップしてみたよ♪'
|
29
|
-
get_movies_list @pickup_uri
|
30
|
-
when /^(.+)#{@suffix}$/
|
31
|
-
get_screen_time($1)
|
32
|
-
@results << 'そんな映画はにゃいっ/(^o^)\' if @results.empty?
|
33
|
-
end
|
34
|
-
|
35
|
-
@results.each { |message| notice(channel, message) }
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def get_movies_list(uri)
|
41
|
-
begin
|
42
|
-
doc = Nokogiri::HTML(open(uri).read)
|
43
|
-
|
44
|
-
movies = []
|
45
|
-
(doc/'h3/a').each do |movie|
|
46
|
-
movies << movie.text.gsub(/ +/, ' ')
|
47
|
-
end
|
48
|
-
|
49
|
-
@results << movies.join(' / ')
|
50
|
-
rescue
|
51
|
-
'/(^o^)\ こわれたっ'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def get_screen_time(search_title)
|
56
|
-
begin
|
57
|
-
expression = Regexp.new(Regexp.quote(search_title))
|
58
|
-
|
59
|
-
@theaters_uri.each do |theater|
|
60
|
-
html = Nokogiri::HTML(open(theater).read)
|
61
|
-
|
62
|
-
if theater.include? 'startheaters'
|
63
|
-
(html/'div.unit_block').each do |movie_info|
|
64
|
-
title = movie_info.at('h3/a').text
|
65
|
-
|
66
|
-
if title =~ expression
|
67
|
-
site = movie_info.at('div.pic_block/a[@target="_blank"]').attributes['href']
|
68
|
-
@results << "#{title.gsub(' ', '')} #{site}"
|
69
|
-
|
70
|
-
(movie_info/'table.set_d').each do |screen|
|
71
|
-
movie = [" - [#{screen.at('th.cinema/img').attributes['alt']}]"]
|
72
|
-
(screen/'td').each do |time|
|
73
|
-
movie << time.text unless time.text.to_i == 0
|
74
|
-
end
|
75
|
-
@results << movie.join(' ')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
else
|
80
|
-
theater_name = '[桜坂劇場]'
|
81
|
-
|
82
|
-
(html/'div.movie').each do |info|
|
83
|
-
movie_title = (info/'div.name/a/span[@dir="ltr"]').text
|
84
|
-
|
85
|
-
if movie_title =~ expression
|
86
|
-
time = info.inner_html.scan(/(..:..+?)</).last
|
87
|
-
@results << "#{theater_name} #{movie_title} #{time} (http://www.sakura-zaka.com/)"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
rescue
|
93
|
-
'/(^o^)\ こわれたっ'
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|