In this Python Tutorial, I would walk you through how to build a trending topic bot using Tweepy and Google News. By the end of this tutorial, you can learn the logic, framework, and mindset of building this bot. You can roll out localized versions based on what markets your business is entering.
Python Modules: Tweepy, Google News, Pandas, datetime, gspread
- Business and Marketing Value of Trending Topic Bot
- Tweepy Trending methods and codings
- Google News API codings
- Trigger Automation using Cron
- Full Python Script of Trending Topic Bot with Tweepy and Google News
Business and Marketing Value of a Trending Topic Bot
Up to date and the trending discussion and topics in the spotlight are like gold for business, this is a kind of a no-brainer. It’s because the content is not only a kind of marketing communication but also a way to leverage events and organic noises to grow sales with a much higher profit margin. Just like Elon Musk, he never invests in marketing to prompt Tesla. And he is a typical icon of well leveraging trending discussion and even creating trending discussion.
However, there is a core formula to leverage content, which is Speed. Speed means reaction to filter information, grab inspiration and deploy a plan applied to the business. And in terms of speed, people must lose to machines. So this is the core value of a trending topic bot.
Tweepy Trending Methods and Codings
Compared to using trending keywords to search topics, it’s much more appropriate to grab the keywords from trending topics. It’s because trending keywords have latency that reflects on the primary platforms such as Google, and Amazon. On the other hand, trending topics that people like to engage and share instinctively have real-time advantages and value for business and marketing.
For more details regarding trending topics with keywords, please refer to this article:
In terms of trending topics by location and country, Twitter uses WOEID to identify a place. Although it doesn’t cover all locations and countries worldwide, the majority of primary cities for business and marketing are on the list. For getting the full list, please refer to the code in the picture below by using the
Then, Tweepy provides a method to grab the trending topics from a place, that is
get_place_trends(). For the argument in the method, we need to input the WOEID number.
Tweepy would respond to the data in a JSON format, which includes the topic name, topic volume, etc. I particularly love the volume data as it helps me with filtering the best engagement content.
Last but not least, the trending content updates every hour and we can schedule the scraping based on the business needs.
Google News API codings
The Google News API is the new search engine result page API. We could use keywords to grab relevant latest news and the event up-to-date information.
First thing first, we need to install the GoogleNews module in your local device environment.
Pip3 install GoogleNews
And in the
GoogleNews() statement, it provides several arguments for us to filter the information, such as the period, in which you can set the latest one-day or one-week news. And then you can select by country, language, etc.
To scrape the data, we need to use two methods, one is
result(). The response data is in the JSON format, so it’s easy to split out the one you aim to grab. The dataset includes the news title, the news source, and the links. Generally, I would also add the date by using the DateTime module as well so that it’s easier for us to identify when the news is
Trigger Automation using Cron
People love using Google alerts to get the relevant latest topic news, however, it has tons of limitations, for example, the filter, and trending topics source. In fact, the automation can be set using Python as well. For more details to set up on your local device, please refer to this article
For the deployment on the Google cloud platform (GCP, I would release another article to walk you through soon.
Full Python Script of Trending Topic Bot with Tweepy and Google News
If you are interested in the full python Tutorial 51 – Trending Topic Bot with Tweepy and Google News API, please subscribe to our newsletter by adding the message “Python Tutorial 51”. We would send you the script immediately to your mailbox.
I hope you enjoy reading python Tutorial 51 – Trending Topic Bot with Tweepy and Google News API. If you did, please support us by doing one of the things listed below, because it always helps out our channel.
- Support my channel through PayPal (paypal.me/Easy2digital)
- Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
- Follow and like my page Easy2Digital Facebook page
- Share the article to your social network with the hashtag #easy2digital
- Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
- You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount code on Buyfromlo products and digital software
- Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)