Daily Latest News webapp Using PyWebio in Python
In this article, we are going to create a web app to get gaily News Using PyWebio
As we all download an app for receiving daily news but as a python lovers we try to do all these things via a python script. So here is a python script that notifies the daily news. In this script, we will create a web app using pywebio which shows all the top headlines as a pop-up window according to the name of country and category of news entered and selected by the user. Here we will extract an API key from the website so that we can extract the latest news and display them in a loop after a particular interval of time as a pop-up window.
- pycountry: pycountry provides the ISO databases for the standards.
pip install pycountry
- pywebio: PyWebIO contains functions for getting user input and output on the browser, turning the browser into a “rich text terminal”, and can be used to build simple web applications or browser-based GUI applications. With this module, anyone can produce a web application without any prior knowledge or overhead of HTML and JS.
pip install pywebio
- newsapi-python: Use the unofficial Python client library to integrate News API into your Python application without having to make HTTP requests directly.
pip install newsapi-python
Step 1: Firstly get your API key from newsapi and then import the following modules.
Step 2: Load an API key(that you have extracted from the website) in a variable and take the name of the country as an input from the user.
Step 3: Now, this function will check that the country name i.e given by the user is valid or not. It checks by storing ISO codes of all the countries in a country dictionary and then if the entered country is not there in the dictionary then it returns an error message.
- Store input country in a variable.
- Create a dictionary and store all the countries in that along with their ISO codes.
- Now if the country name entered by the user is present there in the dictionary then move ahead else return an error message for the invalid country name.
Step 4: Here we get the choice of the user and save the data according to that in variables to display them further.
- Create a list of choice boxes using the radio function so that the user can select the category from which he/she wants to get the news.
- Then use the get_top_headlines function and pass category to it to store all the top latest news in a variable.
Step 5: Now we will print top headlines of news and their content in a loop as a pop-up window after a particular interval of time(you can set that as per your choice in the code below).
Below is the full implementation:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course