Twitter hashing bot

Last night, I wrote a small twitter bot called @hashingbot. If you send it a tweet with a hashing algorithm and some text, it will reply the hash.

Here's an example:

At the moment the following hashing algorithms are supported:

  • md5
  • sha1
  • sha256

The code is based on the sample python autoreply code. When a new message is received, the bot's name is removed and the hashing method is extracted. Finally, the remaining content is used as the parameter to the hashing function.

    def answer(self, tweet):
        try:
            tweet = name_replacer.sub("",tweet).strip()
            cmd = tweet.split(" ")[0]
            text = tweet.replace(cmd, "").strip()
            if cmd == "md5":
                return hashlib.md5(text).hexdigest()
            elif cmd == "sha1":
                return hashlib.sha1(text).hexdigest()
            elif cmd == "sha256":
                return hashlib.sha256(text).hexdigest()
            else:
                return None
        except:
            return None

All in all nothing special ;)

The bot runs on my server, so feel free to try/test it. If you know hashing librarys other than hashlib with useful algorithms for python2.7, feel free to leave a comment and I'll implement them.

-=-