Skip to content

Instantly share code, notes, and snippets.

@yunazuno
Created December 9, 2011 09:19
Show Gist options
  • Save yunazuno/1450853 to your computer and use it in GitHub Desktop.
Save yunazuno/1450853 to your computer and use it in GitHub Desktop.
Post barusu automatically.
#!/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()
#!/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