Introducing Anna

July 22nd, 2008 § 3

This morning I finished the twitter bot I mentioned in my twitter api post. It has been named ‘Anna’ in homage to the Basshunter song. It’s twitter alias is @spsp (st pauls school private). It is written in PHP and is more than just a bit of a hack job as opposed to any quality programming. I have never before done any work with XML so my method of transferring it to a usable array probably deserves a fair bit of criticizm. Anyway, I’ll upload a zip of the script for anyone interested to use, improve on or just comment on.

Purpose:

  • Allows mass invisible messages by reposting a direct message to it to all those following it. (This is invisible as long as the bot itself is ‘protected’, which it is.)
  • Effectively creates a ‘group’ within Twitter.

Usage:

  • Follow @spsp
  • Direct message your message to spsp with the regular syntax. i.e. “d spsp @zethraeus I am testing your excuse-for-a bot”.
  • The message will be reposed as a regular tweet by the bot, without the initial ‘d sps’, but with your twitter alias signed at the end. i.e. the above message would be posted as “@zethraeus I am testing your excuse-for-a bot ~ @alias”.

Limitations:

  • The bot can not handle accented characters. It will cut off your message from the point the accented character is introduced. This is the case because of a quirk in php’s libxml2 functionality – and because I am not a particularly good or dedicated PHP programmer. This quirk is not a bug (apparently).
  • Should your message be above 140 characters once the ‘d spsp’ is removed and your alias is appended, it will be shortened in Twitter, and any clients like Twitterrific. It will require a click through to see the unabridged version. Whilst this isn’t a huge issue, it’s probably worth keeping the tweets a little bit shorter.
  • In theory, if the modified tweet exceeds 160 characters, it may not send. In reality, Twitter wont let you have a name long enough to make this occur in normal usage.
  • The tweets are passed on every five minutes. (This is a cron job)
  • The maximum processable tweets at each 5 minute slot are 20. I don’t know enough about the workings of http://twitter.com/direct_messages.xml to say whether any tweets exceeding the 20 will be lost into Twitter or just processed 5 minutes later.

The script is comprised of three files.

  1. process.php grabs all of @spsp’s direct messages since the last recorded id, records the new last id and reposts the direct messages as tweets.
  2. twitter.php, found at http://www.aimclear.com/code/twitter/twitter.txt is a modified version of the twitter api. It is responsible for actually posting the status.
  3. lastid.txt is simply used to record the id of last read direct message so that tweets aren’t posted twice.

All of these files are available for download and the bits that are mine, are in the public domain for you to do what you want with.

I just hope that people use it!

Tagged: , , ,

§ 3 Responses to “Introducing Anna”

  • Vivan Jayant says:

    I only just discovered your blog, last I saw, zethrae.us was an almost blank page.

    It seems like a good concept but I would never use it as pretty much the only people who follow me are the ones I want to see my tweets.

    A comment on the API: I hate it. All it’s limits can be easily bypassed by NOT using the API, but using normal POSTing through the twitter website using PHP. It’s not at all hard to do and I have a post and get function (originally written to cheat at Neopets, lulz) which work perfectly. I’m making a Twitter based program for my A2 project and I had a good look at the API and decided it was a piece of crap and that it would be much better to do everything the oldschool way.

  • ross says:

    Thanks for sharing your work :)

    I’d be really keen to try the script – but the download link it broken.

    Any chance you could fix/email the zip?

    Cheers,

    Ross

  • adam2z says:

    @ross

    I’ve fixed the link but you’d probably be better off using http://tweetparty.com/

  • § Leave a Reply

What's this?

You are currently reading Introducing Anna at zethrae.us/blog.

meta