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 For world trending topics, the default WOE ID value is 1.


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


  • Reply
    December 11th, 2018 at 23:08

    Nice posts! 🙂

  • Reply
    December 27th, 2018 at 18:33

    Look my site is good

  • Reply
    July 11th, 2019 at 08:52

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

  • Reply
    June 12th, 2020 at 04:03

    Thank You! I used it for my twitter bot of my new blog

  • Leave a Reply