简体   繁体   中英

Stream tweets using tweepy (python) using emoji

I am trying to create an application in python (using tweepy apis) to listen for tweets that include Emojis.

I would like to retrieve all tweets that include the Emoji: 😃, 'U+1F603', '\\xF0\\x9F\\x98\\x83'.

The problem is trying to set up the listener to listen for these tweets.

I am using Spyder and Python 2.7

#Set twitter stream
twitterStream = Stream(auth, listener())
twitterStream.filter(track=[tracker], languages = ["en"], stall_warnings = True, async=True)

This is my code that sets up the stream. This seems to work with any text apart from emojis.

I have tried:

tracker = "\xF0\x9F\x98\x83"
tracker = "U+1F603"

I cannot paste the emoji into the IDE as it turns it into bytes and the above code will listen for the text (bytes or unicode) instead of the emoji itself.

Does any one have any recommendations?

After a lot of research the answer seems quite obvious so I will post it encase others get stuck on a simular problem.

The problem lies with how you handle unicode characters. While some emoji's are 5 characters long they need to be changed.

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

This will need to be changed to:

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

So replace 'u' with 'U000'

I also forgot to surround the unicode with U"\\"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM