Microcosm Twitter Bot Header Image

Microcosm Twitter Bot

I set a goal for #30DayDev January to create a Twitter bot, there weren’t many requirements beyond that it had to retweet people using the hashtag. I can say that after the first week of January I have achieved that goal and released DevMicrocosm into the wild. It followed my rough plan for the project, using Python and Tweepy. This combination of language and library reaffirmed my expectation that it would be quick to develop and deploy.

Due to the Python being able to test commands directly in the terminal, it led to some fantastic opportunities to rapidly prototype some ideas, one of these was to use fully fledged configurations for multiple hashtags. This means that there is no need to redeploy the application every time you want to update what hashtags are being retweeted, you can simply change the config file and the next time the python file is run it’ll use the updated settings.

An example config file for the project can be viewed below. The example demonstrates the simplicity in which multiple hashtags and settings could be defined, I will do an in-depth guide on using the bot in a later post but it is fairly straightforward. These base settings when combined allow for quite a complex behaviour by the bot, leading to better content being shared which in turn produces a higher number of longterm impressions.

{
    "twitter_keys": {
        "consumer_key": "",
        "consumer_secret": "",
        "access_token": "",
        "access_token_secret": ""
    },
    "query_objects": [{
        "search_query": "#test1",
        "tweet_language": "es",
        "tweet_limit": 5,
        "follow_poster": true,
        "user_blacklist": [ "", ""],
        "word_blacklist": ["RT", "♺"],
        "day_to_tweet": 1
    },
    {
        "search_query": "#test2",
        "tweet_language": "en",
        "tweet_limit": 10,
        "follow_poster": false,
        "user_blacklist": [ "", ""],
        "word_blacklist": ["RT", "♺"],
        "day_to_tweet": 1
    }]
}

Rather than reinvent the wheel I opted to fork another repository as a starting point (retweet-bot). I had intended to contribute to this project rather than fork it into my own, however, the original project was no longer being maintained and the extent of the rewrites meant it no longer resembled what it once was, going far beyond the initial projects scope.

If anybody is interested in viewing the code and contributing to the project I made it open-source and the repository can be found here. The readme is slightly out of date but still provides a rough idea on how to run it. I’m looking forward to expanding the bot’s capabilities over the course of the next few months.