Summary:

Set up a Twitter bot to respond to tweets, translating them from English to Independish (American?). @me here

Materials:

To do something like this you need:

  • Twitter account set up as an app
  • Streaming app (using tweepy)

Process:

In the interest of not just documenting projects but also letting others interact with them, let's figure out how to automate replies to a Twitter account. tweepy makes this pretty straightforward with its StreamListener, and Twitter hasn't gotten angry at me yet.

Then, whenever you get a tweet, reply to post, tagging the original account, with their independified translation.

For this application, make sure to only try translating words in our dictionary, which helps a lot with not breaking things.

Code/Algorithms/Etc:

Full codebase can be found here

This code sets up the stream and lets us track ourself.

class Streamer(tweepy.StreamListener):

	def on_status(self, status):
		print(status.text)
		username = status.user.screen_name
		status_id = status.id
		tweet_independence(status.text, username, status_id)

streamer = Streamer()
stream = tweepy.Stream(auth, streamer)
stream.filter(track=['@independify1'])

Taken from here

Then we can hook in our independification code:

def tweet_independence(text, username, status_id):
	api.update_status('@{0} '.format(username) +
                      ' '.join(independify.translate(text)),
                      in_reply_to_status_id=status_id)

where independify.translate is a thin wrapper around the previous code.

Future Work

You could extend this to work with word vectors from any language using any document as a filter. Set it up on its own server too.