Skip to content

Instantly share code, notes, and snippets.

@katsyoshi
Created October 21, 2011 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katsyoshi/1304210 to your computer and use it in GitHub Desktop.
Save katsyoshi/1304210 to your computer and use it in GitHub Desktop.
( ゚∀゚)o彡°おっぱい!おっぱい!
miquire :mui, 'timeline'
Plugin::create(:search_streaming) do
@main = Gtk::TimeLine.new()
@main.force_retrieve_in_reply_to = false
@querybox = Gtk::Entry.new
@querycount = Gtk::VBox.new(false,0)
@searchbtn = Gtk::Button.new('検索')
# savebtn = Gtk::Bu
@queue_parse = SizedQueue.new(2)
@queue_event = TimeLimitedQueue.new(4, 1){ |messages| Delayer.new(Delayer::LAST){ @main.add messages } }
@querycount.closeup(Gtk::HBox.new(false, 0).pack_start(@querybox).closeup(@searchbtn))
@container = Gtk::VBox.new(false,0).pack_start(@querycount,false).pack_start(@main, true)
def keyword( keys )
keys.split(",").map{|k| k.strip}.join(",")
end
def streaming_search( bw )
Thread.new{
@pbzw = nil
loop{
sleep(3)
notice 'filter stream: connect'
begin
break if @pbzw != bw && @pbzw
@pbzw = bw
buzzword = keyword(bw)
if !buzzword or buzzword.empty?
sleep(60)
else
Plugin.call(:rewindstatus, "Searchワード: #{buzzword}")
puts "Searchワード: #{buzzword}"
timeout(60){
@service.streaming(:filter_stream, :track => buzzword){ |word|
@queue_parse.push word
}
}
end
rescue TimeoutError => e
rescue => e
warn e end
notice 'filter stream: disconnected'
}
}
end
def display_search
Thread.new{
loop{
json = @queue_parse.pop.strip
p "JSON:"+json.to_s
case json
when /^\{.*\}$/
messages = @service.__send__(:parse_json, json, :streaming_status) # rescue nil
if messages.is_a? Enumerable
messages.each{ |message|
p message
@queue_event.push message if message.is_a? Message
}
end
end
}
}
end
#def search(word)
Delayer.new {
@service = Post.services.first
Plugin.call(:mui_tab_regist, @container, 'Search')
@searchbtn.signal_connect('clicked'){|elm|
Gtk::Lock.synchronize do
elm.sensitive = @querybox.sensitive = false
@main.clear
streaming_search(@querybox.text)
# streaming_search(UserConfig[:realtime_search])
display_search
elm.sensitive = @querybox.sensitive = true
end
}
}
# end
# search(UserConfig[:realtime_search])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment