Learn how you can become a Python programmer in just 12 weeks.

    We respect your privacy. Unsubscribe at anytime.

    How to Fetch CNN Breaking Tweets and Make Simple Statistics Automated with Python

    What will we cover

    • We will use the tweepy library
    • Read the newest tweets from CNN Breaking
    • Make simple word statistics on the news tweets
    • See if we can learn anything from it


    The Code that does the magic

    import tweepy
    # personal details insert your key, secret, token and token_secret here
    consumer_key = ""
    consumer_secret = ""
    access_token = ""
    access_token_secret = ""
    # authentication of consumer key and secret
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    # authentication of access token and secret
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth)
    # Creation of the actual interface, using authentication
    api = tweepy.API(auth)
    # Use a dictionary to count the appearances of words
    stat = {}
    # Read the tweets from @cnnbrk and make the statistics
    for status in tweepy.Cursor(api.user_timeline, screen_name='@cnnbrk', tweet_mode="extended").items():
        for word in status.full_text.split():
            if word in stat:
                stat[word] += 1
                stat[word] = 1
    # Let's just print the top 10
    top = 10
    # Let us sort them on the value in reverse order to get the highest first
    for word in sorted(stat, key=stat.get, reverse=True):
        # leave out all the small words
        if len(word) > 6:
            print(word, stat[word])
            top -= 1
            if top < 0:

    The result of the above (done May 30th, 2020)

    coronavirus 441
    @CNNPolitics: 439
    President 380
    updates: 290
    impeachment 148
    officials 130
    according 100
    Trump's 98
    Democratic 96
    against 88
    Department 83

    The coronavirus is still the most breaking subject of today.

    Next steps

    • It should be extended to have a more intelligent interpretation of the data.

    Python for Finance: Unlock Financial Freedom and Build Your Dream Life

    Discover the key to financial freedom and secure your dream life with Python for Finance!

    Say goodbye to financial anxiety and embrace a future filled with confidence and success. If you’re tired of struggling to pay bills and longing for a life of leisure, it’s time to take action.

    Imagine breaking free from that dead-end job and opening doors to endless opportunities. With Python for Finance, you can acquire the invaluable skill of financial analysis that will revolutionize your life.

    Make informed investment decisions, unlock the secrets of business financial performance, and maximize your money like never before. Gain the knowledge sought after by companies worldwide and become an indispensable asset in today’s competitive market.

    Don’t let your dreams slip away. Master Python for Finance and pave your way to a profitable and fulfilling career. Start building the future you deserve today!

    Python for Finance a 21 hours course that teaches investing with Python.

    Learn pandas, NumPy, Matplotlib for Financial Analysis & learn how to Automate Value Investing.

    “Excellent course for anyone trying to learn coding and investing.” – Lorenzo B.

    Leave a Comment