Filtering Twitter for emojis

Matt Ramuta | 28 Dec 2014

I'm trying out Twitter Streaming API to check for new tweets that contain some special characters, like emojis. I'm using Tweepy and the biggest challenge I faced, was setting up emoji unicode IDs the correct way.

If I wanted to find an airplane emoji with a 4-digit id like 2708, there were no problems:

stream.filter(track=[u"\u2708"])

But the problem occured when I wanted to use an ID with 5-chars, like 1F602:

stream.filter(track=[u"\u1F602"])

The above code wouldn't work. After some googling I realised that with 5 characters unicode ids you have to do things a little bit different. The thing that worked looks like this:

stream.filter(track=[u"\U0001F602"])

So "U000" (capital u and three zeros) instead of just lowercase "u".

You can see the whole example here: https://github.com/tweepy/tweepy/blob/master/examples/streaming.py

Other useful links: