Twitter data visualisation | CR7
Cristiano Ronaldo’s performance against Atletico Madrid was a masterpiece much like Michelangelo’s The Creation of Adam. So I decided to check CR7’s popularity and public sentiment.
Idea was to get twitter data and draw bubble chart from the hashtags fetched from searching for “#cr7”, then goto the handles/profiles who had tweeted and get other hashtags from their profiles, aggregating and checking for max hashtags used & tweet sentiment.
I had a look at twitter API; there are restrictions like rate limit, request limits etc. Hence I decided to build a NodeJs scrapper using puppeteer to scrape data from twitter page and D3 to render bubble chart on the page.
So first task was to create a simple Nodejs app, and use puppeteer to hit a URL, get data from it. I’ll add the code to goto twitter search URL and query #qwertyuio.
Next task was to scrape data till a particular date. So scroll and check date functionality was needed(twitter loads older tweets on scroll). So I ended up using puppeteer’s scroll functionality. Check the timestamp of the last tweet in the page against the entered date, if its less then scroll further and repeat the process.
Next challenge was to find sentiment from a tweet. Alas I confess my solution here is half baked, as I am not using ML to figure out the sentiment but using an npm package to tokenize the words in the tweet and grade them.
Get Anirvann Das’s stories in your inbox
Join Medium for free to get updates from this writer.
Hence a sentence with words like “f*cking awesome” gets negative sentiments due to the cuss word, where as its usage is meant to enhance the positiveness! I might incline towards GCP sentiment analysis API later on.
Finally..*drum roll* data is here! Lets draw a bubble chart on the browser and see results.
The grey circles are the hashtags extracted by searching for tweets with #cr7. The diameter of the circle is the number of times a hashtag has been used in tweets.
The blue ones are the hashtags which we get the handles(profiles) who had tweeted using #cr7. So many hashtags may be totally irrelevant OR may help derive a pattern!
The sentiment numbers are poor! But in CR7’s defence ( I am a fanboy!) the searches were still going on when I lost patience** and took the screenshot, the sentiment analysis isn’t full proof and it does contain second level of scraping = lot of irrelevant data!
The bubble chart has 10x zoom functionality to read the hashtags :)
Here is the github link to the code.
** If a search is run for very common hashtags, be prepared to wait for a while depending on the number of days added.





