Happened to see Cuba Gooding Jr’s first tweet. At the time his profile said he had 559 followers and it was about 30 minutes or so after he tweeted.
A few minutes later I refreshed his profile and saw the follower count had increased to 590 and every few minutes it kept increasing. By the end of the day he had about 4,000 followers. So thought it would be interesting to use the Twitter API to get his follower count every day and visualize it.
After 2 days Cuba had about 7k followers which averaged out to about 175 new followers per hour. However after he was only getting about 30 or so followers per day. After about 3 months it dropped even more and seems to have flat-lined to 10 or so per day. Some days he has net losses of followers eg more people unfollow than follow him that day.
For the technically inclined, I am getting Tweets using Tweepy Python module setup as a cron job to automatically get Cuba’s follower counts each night (about 12 am PST). The follower counts get put into a database.
I am using PHP to get the data from the database and Google Charts to create a simple line chart to show Cuba’s regularly updated follower count by day.
The Python code that is run by a cron job is below. If you want to run this code yourself you will need a Twitter developer account and an OAuth file.
The PHP web page that gets the data and uses Google Charts is included in this Github repository along with all of this project’s code.
#this runs with cron job every 15 minutes putting follower count into db import tweepy import MySQLdb from datetime import datetime from tweet_auth import * #this is another .py file with the twitter api credentials #connect to db db = MySQLdb.connect(host="localhost", user='myusername', passwd='mypassword', db="mydatabase") # Create a db cursor object to execute queries cur = db.cursor() #get twitter auth auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) #get twitter data users = ['cubagoodingjr'] #datetime for first tweet 'datetime zero' (all datetimes UTC) date_zero = datetime.strptime('2016-02-11 02:35:00', '%Y-%m-%d %H:%M:%S') #current datetime date_now = datetime.now() #calculate diff in hours for this count hours = round((date_now-date_zero).total_seconds() /3600,2) for user in users: user_data = api.get_user(user) cur.execute("INSERT INTO followers_table(user, follower_count, date, hours) VALUES (%s, %s, %s, %s)", (user, user_data.followers_count, date_now, hours)) db.commit() print datetime.now(), 'cubatweet' cur.close() db.close()