Tag Archives: php

Neon shark

Building A Twitterbot

Back in June 2012, I was watching Esc and Ctrl – a series of videos from Jon Ronson for The Guardian, in which he investigates attempts to control the Internet in some way, shape, or form. Some of the videos dealt with Twitterbots, and they piqued an interest on how the bots could generate responses from real Twitter users. As I had free time at lunch I thought I’d investigate how difficult writing a Twitterbot could be.

As it turns out, writing a Twitterbot is remarkably simple. This is probably testament to Twitter’s API – as far as I could tell, pretty much everything I would want to do as a user was available also via the API, and the rich data provided by Twitter was well suited to an application which would effectively parse it in order to generate a response. Additionally, there were plenty of libraries readily available for use in a variety of programming languages, so the barrier to entry was very low. I decided to write one, but I needed an idea for a bot.

Some 5 years earlier, I had read The Raw Shark Texts by Steven Hall. For those who haven’t read it, a brief synopsis: a man named Eric Sanderson is chased by a conceptual shark called a Ludovician, which feeds on words, language, human memory, and the intrinsic sense of self. Eric tries to throw the shark off his scent by travelling through unspace – forgotten tunnels, and abandoned buildings – and the use of other people’s information, writing, and dictaphone recordings. Eric wraps himself in a chaos of others. (As an aside, if you’re interested in the book, I recommend a physical copy, as it is beautifully styled with typography pictures which might lose something in an ebook format).

This felt like a perfect fit for a Twitterbot – what if the Ludovician was searching for Eric on Twitter? A drop of information in an ocean of data would attract it, and there was scope for creating a bit of a mashup. I set off to write it, using PHP for quick development. First, I created an outline of what the script would do:

  1. Search Twitter for references to “Eric Sanderson”, “ludovician”, “luxophage”, or “cognicharius” – these would be rare enough to be people talking about the book, or an exact name match which might entice people to investigate further
  2. For each of the resulting matches, follow any users which weren’t already being followed, store the geo location (if available), and issue a reply to their tweet
  3. Every couple dozen tweets, average out the the locations collected to provide a position for the shark, and provide the likely location of Eric based on the number of matched tweets per location

The responses that the bot would issue would start off as relatively descriptive text, and I was hoping to provide increasing measures of stylised text, much like the book offers, with some specific quotes. This is difficult on Twitter, as ASCII art is limited by the formatting, and there is little control of this on the Twitter site or clients. For this reason I decided to use a technique which was used to great effect on YouTube – superscript and subscript characters. The full list of responses I prepared was as follows:

  • Pattern recognised, following
  • Reincident pattern, targeting
  • Reincident pattern, circling
  • Reincident pattern, increasing priority
  • Memorising pattern
  • Pattern memorised, attempting to locate
  • Location compromised, reverting to data collection
  • Target acquired, deploying luxophage: ·~~-=<{((©@) [defined in the book as a parasite that prevents humans from thinking clearly]
  • Awaiting luxophage attachment
  • Preparing for second stage

  • ȇ̑̐ͫ͗ͣ͒͐͠͏̭̱͕̟̝̀͘͡y͒ͩ­̵̷̜̞̼̼̱͓̬̂͒̉̌͐ͣ̾ͨ͡ͅȩ̧̛͙̤̪̞͕̰̃̓͋̈ͩ̒͗̓ͥͫͧ O ̵͓̳̗͓͖̉͛̆ͩ͐̈́͐͗̂̄ͅe̘͕̞͖̼̘̞͊̑̆̓ͩ̿̈̀y̵̴̛̻̯̟̯̩͒͐̄ͦ̓̆̓͠­̹̣e

  • t̤̦͚̭̙͉̒ͯ̍͂͌̈́̍̌͂̿͘ẽ̝͉̩ͧͯ͗ͣ͢e­̲͍t͙̠̣̽̀̈́̚’ͤ͆ͭ̓ͣ̓ͬ҉͉̜̟̩̯h̲͕̋ͮ ̦̯ͅ ͮ̌̎ͬ̿͆<͕­̘͈V̑̿͋̽͢V̦̻ͧͥ̽͗̎ͩ͟V̹̲͚̗̺͞V͎̬̦͞V̝̥͕ͧ͞>̡̣̯̠̱̪͈ͩ

  • for̽g͌ö̜̯̟́ť͚̱̗̺t͎̝̬̦͂e­̲̼̼̳͕̦̯̚ͅn͕ͣs̯͉̓o̦̜̿͋̽m̟̃ͧͯ͗ͣͅẽͬ̿͆ͩ̎̂͡’͕̯̑̑t͕h̰i̯̟n͚̗̺g͎̬̦i̲͕̦̯ͅmp̷̜o͙̤̪͛̆ṛ̡̯̑̆ͩt̲͕̳̗̦̯ͮ̌̿ͅͅ

  • ̵<­ca̤̦͚̭̒ͯ̍͂͌̈́̍ͅpͯḯṯ͆a̜̞̼̼̬ͅl̷ͦ͗ ̭̦̯ͮ̎̓ͥ ̭̦̯ͮ̎̎͋ͅ O̭̦̯̎̎͋͡ͅ ̭̦̯ͮ̎̎͋ ̭̦̯ͮ̎̎ͥͅ o̵͓͖̺ͦ͗ͅpen>­̵

  • g̰̰̰͂a̰̰̰̰̰͂͂ḭ̰̰̰̰͂͂͂n̰̰̰̰̰͂͂͂͂ḭ̰̰̰̰͂͂͂͂n̰̰̰̰̰͂͂͂͂͂g̰̰̰̰̰͂͂͂͂͂ O̦̦̦̰̎̎̎ f̰̰̰̰̰̰͂͂͂͂a̰̰̰̰̰̰͂͂͂͂͂s̰̰̰̰̰̰͂͂͂͂͂t̰̰̰̰̰̰͂͂͂͂

  • f͚̭͌̈́̍̌i̿ͩ͘͟r̻̯̟͠s̈́͐͗̂̄t͓̳ͅ ҉͉̜̟t̷̜̞͡h͓̬̃̓͋̈ͩͅi̧̛ͥͫͧn͙̤̪g̼̼̱̉͛̆ͩ͐̈́ͅs͕̟̐ͫ͗ͣ ̙͉̿͘f͕̞͖͐̄ͦi̼̱̓̆̓ͅr͏̭̱͕̟̀͡s̤̪̞͕̰͞t̠̱̪̑͋̽
  • h͙̠̣̽̀̈́’a̞̼̼̱ͣ̑͗ͅṛ̡̯̠ͬḑ̧̛͙̤̱̪ͩ ͏̭̱̀͘͡t̳̗͓͖ͧͥ̽͗ͅo̘͕̞͖̼ͦ̓̆̓ ̓ͬ҉͉̜̟s͚̭͂͌̈́̍ḙ̱͕̟ͤ̿͋̽e̲͕̦̯ͤ̑̐ͫ͗ͅ
  • Â̵͓̄ͅq͕̟ͯ͗ͣṳ̪̞ͫ͗ả͛̆ͩr̞͖̼ḯ͙̠u̞̼ͭ̓ͣm’̠̣ͤ͆ ̿͆w̲ͬ̋ͮǎ̧̧͙̎s͓̬̃ͧͯͅ ͕͞g̵̷͛̆ͩ͡i̘͈̓̆̓g̳̗͛̆ͩͅa͕̟̝͋̈ͩṋ̱ͣ͒͐t̟̯̩ͧͥi̱̪͒̉̌c̯̠̱ͣ̾ͨ
  • ȗ̟̝̐n͕ͤ̍͢r̼̼ͯ̈́a̱͕ͭ̍v̟̝ͬ̌e͕̞͖ͣ͗l̦̯͘͡ͅl̘͕̞̒i̠̣ͬ̌̎n̲͍ͤ͆gͩ­͚̭̂ ͏̀t͙̤͞ḧ̤̦́͐͗o͛̆ͩu͓͒̉̌ͅgͧ̽­̘͈h̠̱̪ͮ̌ț͚͒ͩ ҉͉̜̟d’̡̣̯ř̦̯a̼̱ͯg̭ͯ
  • ˙ǝʃqıssod ʎɐʍ ʎɹǝʌǝ uı uɐıɔıʌopn⅂ ǝɥʇ oʇuı ‘ǝɟıʃ ʎW

The final response was based on a separate “fragment” of the novel, which fans of the novel were more likely to have read, and made reference to the Ludovician and Eric becoming tangled.

I had initially considered the idea of taking the geo coordinates and doing a reverse lookup with Google Maps in order to get a near exact address to use in the response, but given the responses planned, I felt it might come across as a little too creepy/menacing.

@Cognicharius avatar
@Cognicharius

The only thing left was to create a Twitter account for the bot. @Ludovician was unfortunately already taken, so I decided on @Cognicharius – the name of the family the Ludovician purportedly belongs to. I used an ASCII art creator to generate an image from a shark photo as its avatar. I set it loose on June 14th 2012, just four lunchtimes after starting.

The bot lived for approximately one year – until the 1.0 Twitter API was retired in June 2013 in favour of the 1.1 API. I didn’t upgrade the bot as I felt the experiment had run its course. In its year of life, @Cognicharius had tweeted 738 times, followed 310 Twitter users, and garnered 91 followers (far more than I can claim). It earned several retweets (including some from Steven Hall himself), generated some amusing responses from people as you can see below, and even got someone to create a Google Map tracking the location of the shark.

Screengrab of Twitter conversation with Cognicharius


Screengrab of Twitter conversation with Cognicharius


Screengrab of Twitter conversation with Cognicharius


Screengrab of Twitter conversation with Cognicharius

Maybe the next bot will just have to message all those users about this blog post.

Photo by staxnet via flickr.