Happy Chinese New Year! Going from Tweets to Trends in Minutes

Chris Lee -
January 31, 2016

Happy Chinese New Year!

With the lunar new year around the corner, we can’t help but wonder what the latest trends are during this special time of the year. These trends are not only interesting but also crucial for goods and service providers to capitalize on this spirit of celebration. Here at indico, we want to demonstrate how quickly and easily these kinds of trends can be found to empower businesses with the knowledge of what people buy and what they care about from potential customers themselves.

In this demonstration, we will be looking at Twitter activity relevant to Chinese New Year approaching the time of the occasion. We will be using Python (2.7+), an unofficial Twitter client library a third party, and indico’s Python client library. Essentially, we will be getting tweets from Twitter, extracting the text and any images, and feeding them to indico’s Keywords API and Image Recognition API.

To forego the technical bits, go ahead and jump to the bottom of the post.

Getting Started

Authentication is always rough, especially for those new to using online APIs. For Twitter, you will need the following:

Consumer Key
Consumer Secret
Access Token
Access Token Secret

To obtain these keys, you will need to:

1. Sign into a Twitter Account
2. Navigate to https://apps.twitter.com/
3. Click Create New App
4. Fill in the details. Feel free to put any placeholder website under Website and leave Callback URL empty.
5. Read and agree to the Developer Agreement
6. Should be navigated to your newly created Application page. Go to Keys and Access Tokens
7. Click Generate My Access Token and Token Secret
8. Now, on this page, you should have access to all 4 keys.

For indico, simply sign into https://indico.io and find your API Key at the top of your dashboard. If you have troubles, chat with us straight from the chat window.

Installation

Assuming you have a development environment (access to a terminal or command prompt), go ahead and install the following:

Now, our tweets object contains all the information about tweets we will need, including the additional analysis by indico! We can perform any kind of analysis on this data. A simple and impactful one is a frequency analysis of the tags we found. Additional tip: if you want to analyze data overtime or play with the data in a sandbox type of environment, we recommend you cache results from Twitter using cPickle (or similar libraries) to avoid being rate-limited by the API.

Now, we have the top thirty keywords and image tags of Twitter statuses. Taking a quick look at some of these tags, we see several keywords, such as “cny”, “chinese”, “celebrate(ing)”. These are obvious keywords given the occasion, so let’s ignore them. We can do this via a blacklist or simply ignore it. There are also nonsense keywords like “https” from links that we can ignore as well. Here’s a little bit of code to do that. Disclaimer: It is slightly inefficient but easy on the eyes.

Keywords

“monkey”: Well, it is the year of the monkey so this makes plenty of sense.

“warriors”: Let’s say we don’t know anything about sports. Here is an example of a tweet it came from:RT @warriors: #Warriors Chinese New Year gear is now available at the @warriors_store! Happy shopping » https://t.co/BuzWyDQ2VV https://t.c\u2026. Looks like the Warriors have Chinese New Year gear, and letting fans know. Chinese New Year themed merchandise is a great way to increase revenue for brands that find that their followers are excited about the year of the monkey.

“manchester”: 'RT @CNY_MCR: Looking for the perfect city to celebrate #ChineseNewYear look no further! https://t.co/Qn0rB7vyyY #Manchester https://t.co/AE\u2026' It looks like the celebration in Manchester’s Chinatown is getting a lot of attention. This is a great opportunity to increase tourism revenue.

“sesame”: New Post on my Blog: Chinese Laughing Sesame Balls (\u7b11\u53e3\u68d7) #ChineseNewYear Snack\n\nRecipe Link:\u2026 https://t.co/QUD3YtKljk' People are super into Chinese sesame recipes! It might be time for fooderies to roll out their special Chinese New Year edition foods.

“hamper” Huh, people must be all about those hampers, or this business found a large number of users to tweet about their giveaway. A little perplexed, but hey, whatever works. 'RT @vegetarianexpre: To celebrate #ChineseNewYear we\u2019re giving away 5 @wingyipstore hampers & 1 deluxe hamper! For a chance to win, follow \u2026', u'To celebrate #ChineseNewYear we\u2019re giving away 5 @wingyipstore hampers & 1 deluxe hamper! For a chance to win, follow & RT.'

There are several, several more, but we’ll leave that as an activity for the reader!

Image Tags

For the most part, the images came with tweets that were captured in the keywords analysis, so these tags should serve to bolster the findings and find popular items that people enjoy sharing. These tags describe the most popular kinds of images that the Image Recognition API picked up on.

book jacket, dust cover, dust jacket, dust wrapper
These tags are quite lengthy, but in general captures specific group of items, such as posters, books, and other flat objects. In our case, it captured both Chinese New Year posters and banners. Several campaigns on Twitter include pictures of advertisements as images and a lot of them will also be captured in this category. There could potentially be a space for new innovative Chinese New Year banners.

carousel, carrousel, merry-go-round, roundabout, whirligig
The Chinese New Year Festivities are being recognized in this category, which kind of makes sense considering there is a limited pre-determined set of tags for image recognition.

envelope
Red Envelopes! This is clearly quite a popular trend. Perhaps, there is a space for long-distance or bulk red envelope giving (electronically or not). Red envelope designs are apparently also something to show off!

jersey, T-shirt, tee shirt
A great way to customize apparel for the Chinese New Year!

plate
Plating the Chinese New Year themed dishes, eat up! If you’re looking for some, The Food Network has some great recipes for you to try at home!

I hope that you’ve enjoyed this tutorial and know that you can use it for not just only the Chinese New Year but for anything you want to dig a little further into. Knowledge is power and in this case, an ultimate competitive advantage!

Feel free to drop me a line at chris@indico.io if you have any questions, need any help, or want to talk use cases for your particular project. We’re all here to help.