In the last post, there were some extra features I implemented that weren’t shown, for brevity and because I considered they deserved a post on their own. So here it is.
The following techniques fall in a category known as Growth Hacking, which consists on using different strategies, techniques and tricks to increase growth. This growth can be defined in different measures depending on your goals, in our case obtaining more followers for our twitterbots.
Autofollow mentioned users
This technique is useful to gain more followers, and it’s simple. It assumes that a percentage of the users the bot follows will follow back, thus increasing the bot’s followers count.
When parsing the tweets from the accounts the twitterbot is following (in the case from the previous post, the tweets of the Spanish Elections candidates), collect all users that are mentioned in their tweets. Then make the twitterbot follow them.
To be more efficient, it can be good to check first if the mentioned users are already followed or not, to save API calls when the bot is following some of the mentioned users. Additionally, the following check can be done in batches of 100 users, so you can save on API usage here too (1 request instead of 100). Also to be more efficient, try to remove duplicate users at the start of the process.
The call to check user friendship it’s not well documented on Tweepy’s documentation, so I had to do some research and check the source code for the actual api call needed (
This technique is useful to gain more exposure. It’s also quite simple. It assumes that tweeting using trending topics will bring the tweets of the twitterbot to bigger audiences, so more potential followers can read the bot tweets.
The key is not to use any (or the most) trending topics but to use only those that are relevant to the activity or context of the twitterbot. Define a list of words of interest for the twitterbot - a whitelist. In this particular case, I use names of candidates and political parties, and also generic concepts that can be related to an election campaign:
whitelist = ['Garzon', 'Garzón', 'IU', 'Iglesias', 'Podemos', 'Mariano', 'Rajoy', 'PP', 'popular', 'Rivera', 'Cs', 'Ciudadanos', 'Sanchez', 'Sánchez', 'castejon', 'PSOE', 'socialista', 'debate', '20d', '20D', 'voto', 'vota', 'elecciones']
Then define the scope of the trending topics, based on the scope of the twitterbot (in the case from the previous post, trending topics for Spain).
You need the WOEID code (acronym for Where On Earth ID) to retrieve trending topics related to a certain location. To obtain the list of locations for trending topics, I used the
trends_available() method of Tweepy, then selected the one that interested me:
Once you get the
woeid in which you are interested, you can obtain the list of trending topics for that location using the
trends_place(woeid) method of Tweepy, which will return a list of JSON objects like this:
In my case, I proxy relevance just by checking if any of the trending topic contains any of the words I’ve defined in the whitelist, but as the API call returns other values, like
tweet_volume, they could be used to compute a different relevance score. Finally, randomly select one of the relevant trending topics.
So here is the final code:
This technique is useful to gain more exposure too, and it’s really straightforward to implement.
Every time the bot starts its tweet with a user mention, prepend a period and the mention gets public.
Combining these techniques, my last twitterbot is growing its follower base at a pace around 10% of its following count, i.e. it has one follower for each ten users it follows, approximately. That’s not very impressive, in terms of overall twitter accounts, however it’s far better than any of my other twitterbots :sweat_smile: