All for Joomla All for Webmasters
Data Mining Python

Tweepy: Retrieving Trending Topics on Twitter for a specific location

One of main applications for Twitter’s content analysis is about watching trending topics, specially because of the microblog’s quality: users are more likely to spread opinions about specific subjects, brands and personalities. That quality provides a good framework for sentiment analysis about those terms and assists the decision-making (in an advertising campaign, for example).

In a previous post, I showed how to implement a tweet collector in Python using Tweepy. To obtain the current network trending topics, the initial steps for Tweepy setup and Twitter application registering are the same. In this case, the additional argument you’ll need to run the code is the WOE (Where On Earth) ID, which sets the location from where the topics will be retrievied. You can obtain the WOE ID for a specific location on http://woeid.rosselliot.co.nz/. For world trending topics, the default WOE ID value is 1.

THE SOURCE CODE

If you’re already familiar with Tweepy library, the code above may be easy to understand. The method trends_place returns a set of objects with information about the topics in JSON format, so I used the dump method from JSON standard library to parse the data. In this example, the algorithm only prints the title of the topic, only to show how to manipulate the object. One of the benefits from using the API’s method is the amount of topics retrieved are significantly greater than the web platform (that shows only 10 topics at a time). If you have any doubts or suggestions, please use the comment area or contact me.

You Might Also Like

3 Comments

  • Reply
    Sannytet
    December 11th, 2018 at 23:08

    Nice posts! 🙂
    ___
    Sanny

  • Reply
    Sannytet
    December 27th, 2018 at 18:33

    Look my site is good
    ___
    http://afcmarseille.com

  • Reply
    Ajay
    July 11th, 2019 at 08:52

    hi, i am getting same hashtags data for different town of India.

  • Leave a Reply