I see Dave has posted a few ideas that he’d like to be able to do with Twitter. His ‘use case #1′ is regarding the ability to subscribe to a kind of ‘reading list’ of people at a conference. Good idea! TwitterGroups are what we need! :)
So, while I was at Gnomedex, I wanted a way to track tweets (that’s Twitter posts, for the uninitiated ;p ) from others at the conference who were also on Twitter. A show of hands from the audience showed there were a LOT of us ;) Naturally, I don’t want to have to follow every user and see everypost/tweet from them – I just want the ones relevant to the conference.
Having got the idea of how to do it in my head in the first morning session, I hacked it together quite quickly during the lunchbreak. It’s based very much like my Urban Dictionary ‘TwitterBot’ which will go and search for the (urban) meaning of a word, at the command of any follower.
So, here’s how I did it:
1. First, I set up an account, called @gnomenet
2. Then I set up a simple database table in MySql with a ‘status_id’ column and a ‘screen_name’ column.
3. I then invited people to ‘follow’ that account and instructed the followers to start a post with ‘gd’ if they wanted their tweet to appear in the ‘group’ timeline – if they had something to say about the conference.
4. Then, I had a PHP script set on an automated cronjob to poll the followers.xml for the gnomenet account. The followers.xml file always has the latest tweet from each follower, also providing the status(tweet) id and the follower’s screen name. It polled the followers.xml file once a minute, which is under Twitter’s API limit of 70 per hour.
5. When the script sees ‘gd’ at the start of a follower’s tweet, it then adds the screen_name and status_id to the database table. Then it sends that Tweet to the @gnomenet account after removing ‘gd ‘ from the start. This is easily done using Twitter’s very simple API.
6. The next time the script polls the followers.xml file, if it sees the same user posting the same thing (it compares each status_id with existing records in the database) it says to itself “this user already said that!” and ignores it.
7. If the follower does not have gd at the start of the Tweet, then the script goes and deletes from the database table any post from that user/screen_name – ie: mostly, there is nothing to delete, as people don’t post to it all the time.
Doing this keeps the database table clean and compact. It worked pretty well for 52 followers! I wonder how many them were not even there at the conference! :)
This has a load of potential uses for TwitterBot automation and TwitterGroup creation, though I’m sure there might be a more graceful way of doing this. Happy to hear more ideas
Gnomedex was GREAT fun again – this was my third. But I have to say, I’m looking forward to the possibility of ‘GnomeStock‘ ;p