I was approached recently by a band who wanted to promote their latest song on Twitter. They knew that a lot of people were talking about them online and they wanted to use that conversation to highlight their new single. This made perfect sense; people already were talking about them, what better time is there to highlight their new music?!
We discussed a tool whereby we would search for people who mentioned them in a tweet and respond to those users with a link to their latest song. This was an interesting task with some interesting challenges.
1. What tweets should we look for?
Any tweets containing the bands name or their twitter handle
2. What tweets should we reply to?
The tweets are validated to see if they are worth responding to:
- Has the bot already tweeted this person?
- Has the tweet got any negative words in it that we want to avoid?
- Is the tweet a RT, and if so, do we want to ignore this?
- Has this tweet been responded to before? If any of these are true, we should ignore the tweet.
Otherwise, we will respond with a choice of replies
- Has the tweet got the name of the bands latest song in it? Wouldn’t we want ensure we don’t send them back the same song? We would look like lunatics! Example:
- Twitter User: I like Ice Cream!
- Bot: Hey, have you heard about Ice Cream??!!!
3. Lets friend request the people tweeting about us!
This is useful as you can send a friend request which won’t execute if they are already a follower!
4. How will we record the data?
I use the pickle module here to record all tweets we respond to. This data informs future validation checks! Awesome…
5. When will we run it?
Daily of course! A borg file will execute the python file every night!
Finally, after a lot of testing, we had a working tool which would :
- Fetch x amount of tweets every day
- Decide whether it should reply
- Respond with a link to the song or not depending on the tweet content
- Record all data and use for future decisions
The band was very happy and I thoroughly enjoyed the process. Tweepy is an awesome Python library that makes querying the Twitter API painless. If you want to check out the code, head over to my github!