Last active
December 18, 2015 01:09
-
-
Save wstrinz/5702026 to your computer and use it in GitHub Desktop.
Twitter bot that parses tweets into their components.
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
require 'rubygems' | |
require 'chatterbot/dsl' | |
require 'imgur' | |
require 'treat' | |
require 'yaml' | |
require 'pastebin' | |
include Treat::Core::DSL | |
verbose | |
update_config | |
Imgur.client_id = #get your own here https://api.imgur.com/oauth2/addclient | |
loop do | |
none = true | |
replies do |tweet| | |
puts "reply" | |
none = false | |
message = tweet.text | |
message.slice!("@parsetree") | |
parsed = entity(message.dup.strip.chomp).apply(:chunk, :segment, :tokenize, :tag, :parse) | |
parsed.visualize :dot, file: 'parsed_tree.dot' | |
`dot -Tpng parsed_tree.dot -o parsed_tree.png` | |
img = Imgur.upload_file('./parsed_tree.png') | |
answer = "@" + tweet.user.screen_name + " " + Pastebin.new(api_paste_code: parsed.visualize).paste + " imgur.com/" + img[:hash] | |
puts answer | |
reply answer, tweet | |
end | |
update_config | |
if none | |
sleep(60) | |
else | |
sleep(60) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment