Created
December 9, 2011 09:19
-
-
Save yunazuno/1450853 to your computer and use it in GitHub Desktop.
Post barusu automatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
require "julius" | |
require "twitter" | |
Twitter.configure do |config| | |
config.consumer_key = '' | |
config.consumer_secret = '' | |
config.oauth_token = '' | |
config.oauth_token_secret = '' | |
end | |
def post_barusu() | |
sleep(65) | |
Twitter.update('バルス!') | |
end | |
def main() | |
juli = Julius.new() | |
juli.connect() | |
while true | |
words = juli.word() | |
if words.index('三') then | |
post_barusu() | |
#break | |
end | |
end | |
end | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
# | |
# Get words from julius | |
# based on: http://d.hatena.ne.jp/kenkitii/20091224/p1 | |
# | |
require "socket" | |
require "rubygems" | |
require "nokogiri" | |
class Julius | |
@sock = nil | |
def initialize() | |
# | |
end | |
def connect(host = "localhost", port = 10500) | |
@sock = TCPSocket.open(host, port) | |
end | |
def word() | |
source = "" | |
while true | |
ret = IO::select([@sock]) | |
ret[0].each do |juli| | |
source += juli.recv(65535) | |
if source[-2..source.size] == ".\n" | |
source.gsub!(/\.\n/, "") | |
xml = Nokogiri(source) | |
words = (xml/"RECOGOUT"/"SHYPO"/"WHYPO").inject("") {|ws, w| ws + w["WORD"]} | |
unless words.empty? | |
return words | |
end | |
source = "" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment