To start using Desktop News Notifier, we need two libraries: feedparser and notify2.
Issue the following command to install feedparser:
sudo pip3 install feedparser
To install notify2 in your terminal:
sudo pip3 install notify2 pre >
Feedparser will parse the feed we receive from the URL. We will be using notify2 for desktop notifications. Apart from these two libraries, we will be using the OS and the temp library. After the installation is complete, import both libraries into the program. Here in this example I analyzed news from BBC UK, you can use any news feed url. Let`s take a look at the program:
Screenshot of news notification toast
Step by step / br >
f = feedparser.parse ("http://feeds.bbci.co.uk/news/rss.xml")
Here feedparser will parse the news data from the feed url. The parsed data will be in the form of a dictionary.
ICON_PATH = os.getcwd () + "/icon.ico"
If you want to set any icon in the notification , then here we set the path to the icon. This is optional.
notify2.init (`News Notify`)
Here we initialize notify2 using the init method of notify2. Initialize the D-Bus connection. Must be called before you send any notifications or receive information or server capabilities.
for newsitem in f [`items`]: n = notify2.Notification ( newsitem [`title`], newsitem [` summary`], icon = ICON_PATH)
Cycle through the parsed data to retrieve relevant information such as news title, brief summary, and setting a notification icon using the Notification2 method in lib notify2.
Set the urgency to one of URGENCY_LOW, URGENCY_NORMAL or URGENCY_CRITICALli >
This method will show a desktop notification
Sets the time to save the notification on the desktop (in milliseconds). I set it here as 15 seconds.
Usually this will display a news notification every 20 minutes. You can set the time as per your requirement. You can find the full source code at GitHubli >
This article is courtesy of Srce Cde . If you like Python.Engineering and would like to contribute, you can also write an article using contrib.python.engineering, or email your article to [email protected] See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you`d like to share more information on the topic discussed above.
As information protection continues to be a growing concern for businesses today, IT security certifications have become highly desirable, even as the number of certifications has grown. Now you can s...
Data scientist has been called “the sexiest job of the 21st century,” presumably by someone who has never visited a fire station. Nonetheless, 23/09/2020
Acquire and analyze data from all corners of the social web with Python. This book is for intermediate Python developers who want to engage with the use of public APIs to collect data from social m...
Mastering regular expressions by Jeffrey Friedl, 3rd edition. Regular expressions are an extremely powerful tool for manipulating text and data. They are standard features today in a variety of pop...