/ tuesdaytooling

Tooling Tuesday: Catch the news!

Right now there is a lot of news going on, stay informed!

So what is it?

Newscatcher is a Python library to collect the news from the top one thousand websites using the Newscatcher API

So how do I install it?

Via pip!

Linux / Mac

pip3 install newscatcher


pip install newscatcher

So how do I use it?

First we need to import the Newscatcher library into our code.

from newscatcher import Newscatcher

Then we tell the library which website we want to get the news from. In this case the New York Times.

website = Newscatcher('nytimes.com')

The URL (web address) of the site should have no http:// or www, for example bigl.es rather than https://bigl.es.

Now we get the top ten headlines from that website.

website.print_headlines(n = 10)

Running these few lines in the Python REPL I received this output.

1.   |  Coronavirus Live Updates: Costs of Containment Grow; New York City Braces for a Deluge of Patients
2.   |  Global Stocks Rally on Hopes of a U.S. Economic Deal: Live Updates
3.   |  Trump Considers Reopening Economy, Over Health Experts’ Objections
4.   |  Democrats Again Block Action on Coronavirus Stimulus, Seeking Restrictions on Corporate Aid
5.   |  How an Upscale Connecticut Party Became a Coronavirus 'Super Spreader'
6.   |  Free Access to Coronavirus Coverage
7.   |  Trump Has Given Unusual Leeway to Fauci, but Aides Say He’s Losing His Patience
8.   |  In Daily Coronavirus Briefing, Trump Tries to Redefine Himself
9.   |  Texas and Ohio Include Abortion as Medical Procedures That Must Be Delayed
10.  |  Dip in Italy’s Cases Does Not Come Fast Enough for Swamped Hospitals

We cannot get the news from every website, for example I tried BBC News and The Guardian and I got an exception error message Exception: website is not supported

Your help makes this blog possible!
Sorry to interrupt! It would be great if you could buy me a cup of coffee / make a donation via Ko-Fi. It helps me to pay for hosting this blog, and to buy stuff to hack from Poundshops / Dollar Stores / Aliexpress which are used in free projects on this blog. Thanks!

So can we build a quick project with this?

This nine line Python script will create a quick app to send the top three headlines from wired.co.uk to the desktop as notifications. For this I installed the notify2 Python library.

pip3 install notify2

Here is all the code!

import notify2, time
from newscatcher import get_headlines
news = get_headlines('wired.co.uk')
notify2.init("Latest News from Wired.co.uk")
for i in range(3):
    n = notify2.Notification(news[i])

I also print each headline to the REPL for debug.