twink 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +15 -0
- data/README +3 -0
- data/Rakefile +51 -0
- data/lib/cameliatk/schedule_factory.rb +178 -0
- data/lib/cameliatk/string_extension.rb +25 -0
- data/lib/cameliatk/twitter_feed.rb +79 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
== twink
|
2
|
+
|
3
|
+
Copyright(c) 2009 The Camelia Framework Foundation
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# To change this template, choose Tools | Templates
|
3
|
+
# and open the template in the editor.
|
4
|
+
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rake'
|
8
|
+
require 'rake/clean'
|
9
|
+
require 'rake/gempackagetask'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
require 'rake/testtask'
|
12
|
+
require 'spec/rake/spectask'
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.name = 'twink'
|
16
|
+
s.version = '0.1.0'
|
17
|
+
s.has_rdoc = false
|
18
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
19
|
+
s.summary = 'cameliaTk twink'
|
20
|
+
s.description = s.summary
|
21
|
+
s.author = 'The Camelia Framework Foundation'
|
22
|
+
s.email = 'jury@cameliatk.jp'
|
23
|
+
# s.executables = ['your_executable_here']
|
24
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
|
25
|
+
s.require_path = "lib"
|
26
|
+
s.bindir = "bin"
|
27
|
+
s.add_dependency('twitter', '>=0.6.12')
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::GemPackageTask.new(spec) do |p|
|
31
|
+
p.gem_spec = spec
|
32
|
+
p.need_tar = true
|
33
|
+
p.need_zip = true
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
files =['README', 'LICENSE', 'lib/**/*.rb']
|
38
|
+
rdoc.rdoc_files.add(files)
|
39
|
+
rdoc.main = "README" # page to start on
|
40
|
+
rdoc.title = "cameliaTk twink Docs"
|
41
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
42
|
+
rdoc.options << '--line-numbers'
|
43
|
+
end
|
44
|
+
|
45
|
+
Rake::TestTask.new do |t|
|
46
|
+
t.test_files = FileList['test/**/*.rb']
|
47
|
+
end
|
48
|
+
|
49
|
+
Spec::Rake::SpecTask.new do |t|
|
50
|
+
t.spec_files = FileList['spec/**/*.rb']
|
51
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# Copyright @year@ @owner@
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# $Id:$
|
16
|
+
require 'date'
|
17
|
+
require 'time'
|
18
|
+
require 'parsedate'
|
19
|
+
require 'cameliatk/string_extension'
|
20
|
+
|
21
|
+
#
|
22
|
+
# ���b�Z�[�W�t�H�[�}�b�g
|
23
|
+
# MTG:��${phrase}
|
24
|
+
# ��: ���pSP
|
25
|
+
#
|
26
|
+
# ${phrase}�̃t�H�[�}�b�g
|
27
|
+
# ���t�A�J�n���ԁA�I�����Ԃ��w�肵�܂��B
|
28
|
+
# ���t�ƏI�����Ԃ͏ȗ��ł��܂��B
|
29
|
+
# ���t���ȗ������ꍇ�͓����̗\��Ƃ݂Ȃ��܂��B
|
30
|
+
# �I�����Ԃ��ȗ����ꂽ�ꍇ�͍ŏ����ԒP�ʂ̗\��Ƃ݂Ȃ��܂��B
|
31
|
+
#
|
32
|
+
# 1) �����̎��Ԏw��̗\��
|
33
|
+
# ${stime}��${meeting}
|
34
|
+
# 2) �����̎��ԑюw��̗\��
|
35
|
+
# ${stime}��${etime}��${meeting}
|
36
|
+
# 3) �w������̗\��
|
37
|
+
# ${date}��${stime}��${meeting}
|
38
|
+
# 4) �w����̎��ԑюw��̗\��
|
39
|
+
# ${date}��${stime}��${etime}��${meeting}
|
40
|
+
#
|
41
|
+
# ${date}�̃t�H�[�}�b�g
|
42
|
+
# 1)
|
43
|
+
# YYYY/mm/dd
|
44
|
+
# 2)
|
45
|
+
# mm/dd
|
46
|
+
#
|
47
|
+
# ${stime}�A${etime}�̃t�H�[�}�b�g
|
48
|
+
# 1)
|
49
|
+
# HH:MM:SS
|
50
|
+
# 2)
|
51
|
+
# MM:SS
|
52
|
+
#
|
53
|
+
# ${meeting}�̃t�H�[�}�b�g
|
54
|
+
# ${titile}�ɔ��p�������܂ނ��Ƃ͂ł��܂��A${place}�ɂ͎g�p���邱�Ƃ��ł��܂��B
|
55
|
+
# ${place]�͏ȗ��\�ł��B
|
56
|
+
#
|
57
|
+
# 1) �\��^�C�g���̂�
|
58
|
+
# ${title}
|
59
|
+
# 2) �\��^�C�g���Əꏊ
|
60
|
+
# ${title}(${place})
|
61
|
+
#
|
62
|
+
|
63
|
+
Struct.new "Schedule", :twitter_id, :message_id, :date, :stime, :etime, :title, :place, :posted_at, :phrase
|
64
|
+
|
65
|
+
module Cameliatk
|
66
|
+
class ScheduleFactory
|
67
|
+
|
68
|
+
def self.get string=nil
|
69
|
+
return nil unless string
|
70
|
+
|
71
|
+
schedat = parse string
|
72
|
+
return nil if schedat.nil?
|
73
|
+
return nil if schedat.empty?
|
74
|
+
|
75
|
+
schedule = Struct::Schedule.new
|
76
|
+
schedule.date = schedat[:date]
|
77
|
+
schedule.stime = schedat[:stime]
|
78
|
+
schedule.etime = schedat[:etime]
|
79
|
+
schedule.title = schedat[:title]
|
80
|
+
schedule.place = schedat[:place]
|
81
|
+
schedule.posted_at = schedat[:posted_at]
|
82
|
+
schedule.phrase = schedat[:phrase]
|
83
|
+
|
84
|
+
schedule
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.get_phrase string=nil
|
88
|
+
re = /MTG:(.*)/
|
89
|
+
if string =~ re
|
90
|
+
$1.strip
|
91
|
+
else
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.parse string=nil
|
97
|
+
rtn = {}
|
98
|
+
return rtn unless string
|
99
|
+
|
100
|
+
rtn[:phrase] = get_phrase string
|
101
|
+
if rtn[:phrase]
|
102
|
+
words = split_sp rtn[:phrase]
|
103
|
+
|
104
|
+
hash = {}
|
105
|
+
words.each do |word|
|
106
|
+
if hash[:message].nil? && word.looks_like_time?
|
107
|
+
unless hash.key? :stime
|
108
|
+
hash[:stime] = word
|
109
|
+
else
|
110
|
+
hash[:etime] = word
|
111
|
+
end
|
112
|
+
elsif hash[:message].nil? && word.looks_like_date?
|
113
|
+
hash[:date] = word
|
114
|
+
else
|
115
|
+
if hash[:message]
|
116
|
+
hash[:message] = hash[:message] + " " + word
|
117
|
+
else
|
118
|
+
hash[:message] = word
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
if hash.key? :date
|
124
|
+
rtn[:date] = to_date hash[:date]
|
125
|
+
else
|
126
|
+
rtn[:date] = Date::today
|
127
|
+
end
|
128
|
+
if hash.key? :stime
|
129
|
+
rtn[:stime] = to_time(rtn[:date],hash[:stime])
|
130
|
+
end
|
131
|
+
if hash.key? :etime
|
132
|
+
rtn[:etime] = to_time(rtn[:date],hash[:etime])
|
133
|
+
end
|
134
|
+
if hash.key? :message
|
135
|
+
if hash[:message] =~ /(.*)\((.*)\)/
|
136
|
+
rtn[:title] = $1.strip
|
137
|
+
rtn[:place] = $2
|
138
|
+
else
|
139
|
+
rtn[:title] = hash[:message]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
rtn
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.split_sp string=nil
|
148
|
+
rtn = []
|
149
|
+
return rtn unless string
|
150
|
+
|
151
|
+
rtn = string.split /([\S]*\([^\)]*\)|\S+)/
|
152
|
+
rtn.reject {|x| x.nil? || x.to_s.strip.empty?}
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.to_time date, str=nil
|
156
|
+
return str unless str
|
157
|
+
arr = ParseDate::parsedate str
|
158
|
+
h,m,s = arr[3..5].map {|x| x.nil? ? 0 : x}
|
159
|
+
return Time::local(date.year, date.month, date.day, h, m, s)
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.to_date str=nil
|
163
|
+
return str unless str
|
164
|
+
arr = ParseDate::parsedate str
|
165
|
+
y,m,d = arr[0..2]
|
166
|
+
return nil if (m.nil? || d.nil?)
|
167
|
+
unless y
|
168
|
+
today = Date::today
|
169
|
+
if (m < today.month)
|
170
|
+
y = Date::today.year + 1
|
171
|
+
else
|
172
|
+
y = Date::today.year
|
173
|
+
end
|
174
|
+
end
|
175
|
+
return Date::new(y,m,d)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright(c) 2009 The Camelia Framework Foundation
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# $Id:$
|
16
|
+
|
17
|
+
class String
|
18
|
+
def looks_like_date?
|
19
|
+
return self =~ /^\d{1,2}\/\d{1,2}$|^\d{2,4}\/\d{1,2}\/\d{1,2}$/
|
20
|
+
end
|
21
|
+
|
22
|
+
def looks_like_time?
|
23
|
+
return self =~ /^\d{1,2}\:\d{1,2}$|^\d{1,2}\:\d{1,2}:\d{1,2}$/
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'twitter'
|
3
|
+
require 'cgi'
|
4
|
+
require 'cameliatk/schedule_factory'
|
5
|
+
|
6
|
+
module Cameliatk
|
7
|
+
|
8
|
+
class TwitterFeed
|
9
|
+
attr_reader :login
|
10
|
+
attr_accessor :keyword
|
11
|
+
|
12
|
+
def initialize opts={}
|
13
|
+
@options = {}
|
14
|
+
@options.merge!(opts)
|
15
|
+
@login ||= @options[:login]
|
16
|
+
|
17
|
+
Twitter::HTTPAuth.http_proxy( @options[:proxy_addr], @options[:proxy_port] )
|
18
|
+
@httpauth = Twitter::HTTPAuth.new @options[:login], @options[:password], @options
|
19
|
+
@twitter = Twitter::Base.new( @httpauth )
|
20
|
+
end
|
21
|
+
|
22
|
+
def feed query={}
|
23
|
+
@twitter.user_timeline(query).map{|m| [m.id, CGI.unescapeHTML(m.text)]}
|
24
|
+
end
|
25
|
+
|
26
|
+
def mentions query={}
|
27
|
+
@twitter.mentions(query).map{|m| [m.id, m.created_at, CGI.unescapeHTML(m.text)]}
|
28
|
+
end
|
29
|
+
|
30
|
+
DEFAULT_KEYWORD = 'MTG:'
|
31
|
+
|
32
|
+
def schedule_messages query={}
|
33
|
+
msgs = mentions query
|
34
|
+
msgs ||= []
|
35
|
+
schedules = []
|
36
|
+
word = @keyword
|
37
|
+
word ||= DEFAULT_KEYWORD
|
38
|
+
msgs.each do |x|
|
39
|
+
msgid, mcreated_at, msg = x
|
40
|
+
msg.gsub!(/@#{@login}/,'')
|
41
|
+
if msg =~ /#{word}/
|
42
|
+
schedules << [msgid,mcreated_at,msg]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
schedules
|
46
|
+
end
|
47
|
+
|
48
|
+
def update msg=nil
|
49
|
+
if msg
|
50
|
+
@twitter.update CGI.escapeHTML(msg)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_schedules opt={}
|
55
|
+
schedules = []
|
56
|
+
msgs =schedule_messages opt
|
57
|
+
msgs.each do |x|
|
58
|
+
msgid,mcreated_at,msg = x
|
59
|
+
sche = Cameliatk::ScheduleFactory.get msg
|
60
|
+
if sche
|
61
|
+
sche.twitter_id = @login
|
62
|
+
sche.message_id = msgid
|
63
|
+
sche.posted_at = mcreated_at
|
64
|
+
schedules << sche
|
65
|
+
end
|
66
|
+
end
|
67
|
+
schedules
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
module Twitter
|
74
|
+
class Base
|
75
|
+
def mentions(query={})
|
76
|
+
perform_get('/statuses/mentions.json', :query => query)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twink
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- The Camelia Framework Foundation
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-09 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: twitter
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.6.12
|
24
|
+
version:
|
25
|
+
description: cameliaTk twink
|
26
|
+
email: jury@cameliatk.jp
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README
|
37
|
+
- Rakefile
|
38
|
+
- lib/cameliatk/twitter_feed.rb
|
39
|
+
- lib/cameliatk/string_extension.rb
|
40
|
+
- lib/cameliatk/schedule_factory.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage:
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: cameliaTk twink
|
69
|
+
test_files: []
|
70
|
+
|