Created
May 11, 2012 13:28
-
-
Save inutano/2659615 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
require "yaml" | |
require "twitter" | |
def force_mecab_parse(y_conf, text) | |
mecabed = `echo "#{text}" | /opt/local/bin/mecab`.split("\n") | |
parsed_arr = mecabed.map do |line| | |
tab_sep = line.split("\t") | |
com_sep = tab_sep.map{|p| p.split(",") } | |
com_sep.flatten | |
end | |
nouns = parsed_arr.select{|p| p[1] == y_conf["feature"] } | |
filtered = nouns.delete_if{|p| y_conf["ng_words"].include?(p[0]) } | |
filtered.map{|p| p.first }.sort_by{|n| n.length }.last | |
end | |
def decorate(y_conf, noun) | |
headers = y_conf["headers"] | |
normal_footer = y_conf["normal_footer"] | |
special_footers = y_conf["special_footers"] | |
dagger = y_conf["dagger"] | |
lucky = rand | |
if lucky < 0.07 | |
dagger + noun + dagger | |
elsif lucky < 0.2 | |
noun + special_footers.sample | |
elsif lucky < 0.3 | |
headers.sample + noun + normal_footer | |
else | |
noun + normal_footer | |
end | |
end | |
if __FILE__ == $0 | |
current = "#{File.expand_path(File.dirname(__FILE__))}" | |
y_conf = YAML.load_file("#{current}/config.yaml") | |
tw_conf = y_conf["twitter"] | |
Twitter.configure do |config| | |
config.consumer_key = tw_conf["consumer_key"] | |
config.consumer_secret = tw_conf["consumer_secret"] | |
config.oauth_token = tw_conf["access_token"] | |
config.oauth_token_secret = tw_conf["access_token_secret"] | |
end | |
tw = Twitter::Client.new | |
received = tw.home_timeline({ :exclude_replies => true }) | |
not_mine = received.delete_if{|t| t.user.screen_name == "mickey24dono" }.sample | |
filtered = not_mine.text.gsub(/http.+?( |$)/,"").gsub(/@.+? /,"") | |
noun = force_mecab_parse(y_conf, filtered) | |
lucky = rand | |
if !noun or lucky < 0.2 | |
tw.update(y_conf["monologues"].sample) | |
else | |
decorated = decorate(y_conf, noun) | |
tw.update(decorated) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment