Molly White
Software engineer, editor and arbitrator on Wikipedia, feminist, Twitter bot commander, unabashed cat lady.

The rise of the cyberbot

When I first saw Darius Kazemi's Cyberpunk Fiction Machine, all I could think of were the various tech-related articles that try to make things sound more hacker-y and doom-and-gloom by prefixing every noun with "cyber". Take for example "Hostile Takeover: Now the NSA Wants to Snoop on Wall Street, too" from Foreign Policy, which speaks of "cyberpackets" and "one fell cyberswoop." This ridiculous trend seemed perfect for a Twitter bot, something I'd always wanted to try.

After a lot of Googling, I managed to patch together @CyberPrefixer (source). I was really pleased with how easy it was to create. First I use BeautifulSoup to parse the HTML that's pulled in from Google News' RSS feed. Once I extract the headlines, I weed out any truncated headlines (ones that end in "...") to avoid awkward half-headlines. I also throw away any headlines that are in title case, as I wanted to avoid having to try to convert them to sentence case without losing proper nouns. I remove the attribution string that follows, then pass the headline along to topia.termextract to tag the parts of speech in the headline. Once this is done, I prefix "cyber" to any noun that begins with a lowercase letter, unless the word before it also begins with "cyber." I considered not adding this last check, but found that headlines like "China says it monitored US B 52s that flew through its new cyberair cyberzone" were just getting ridiculous. Once the headline is selected and processed, I use tweepy to check that the bot hasn't already tweeted this headline, and send it out! I have the bot running on an hourly cron job, and have been enjoying the tweets it's already created.

I'm glad to have this basic framework, because if (when?) I decide to make any more Twitter bots, I'll be able to just modify this. If anyone happens to like Python2 and wants to create a Twitter bot, feel free to fork it, although I can't imagine it's the most elegant bot framework that's out there.

comments powered by Disqus