Fetching top news using News API
News API is a simple JSON-based REST API for searching and retrieving news articles from all over the web. Using this, one can fetch the top stories running on a news website or can search top news on a specific topic (or keyword).
News can be retrieved based on some criteria. Say the topic (keyword) to be searched is ‘Geeksforgeeks’ or might be concerned to a specific channel. All can be done, but the API key is needed to get started.
Steps : 1. Visit https://newsapi.org/ to get your own API key. 2. Install requests package.
Below is the implementation of the above idea :
1 Italy to lift coronavirus travel restrictions 2 White House 'Operation Warp Speed' to look for Covid jab 3 Two Americas in the nation's capital 4 Kobe Bryant helicopter crash post-mortem released 5 Little things people are doing while socially distanced 6 The last 'normal' photo on your phone 7 'They came to kill the mothers' 8 EU-UK Brexit trade talks in trouble 9 Trial starts to see if dogs can 'sniff out' virus 10 Beatles photographer Astrid Kirchherr dies aged 81
Note: Output may change based on the top articles at the time.
This approach will work as a cherry on a cake because it will display the news according to the category entered by the user so as work as a filter for those who want to know the news in a particular category/section.
First of all install newsapi and pycountry in your system if it’s not there the install using the command below:
~ pip install newsapi-python ~ pip install pycountry
Country: India Which category are you interested in? 1.Business 2.Entertainment 3.General 4.Health 5.Science 6.Technology Enter here: Technology
Gizbot News: Garena Free Fire Redeem Codes For August 16; Get Master of Minds Weapon Loot Crate. News18: Google Pixel 5a Will Have Biggest Battery On Any Pixel Phone Ever, Launch This Month. Hindustan Times News: PUBG Mobile: Here’s how to get the Unhinged Mortician set on PUBG Mobile, check details of RPM2 Royale Pass. Times of India News: New iPhones, Watch, AirPods and more: What Apple may launch in September. GSMArena.com News: Top 10 trending phones of week 32 - GSMArena.com news. Hindustan Times News: Study finds if 'people persons' are 'machine persons' when they interact online. Times of India News: 2021 vs 2020: August gasps for one ‘good’ air day in Gurugram this year. ScienceAlert News: A Simple Crystal Could Finally Give Us Large-Scale Quantum Computing, Scientists Say. Engadget News: The Switch is the first console to sweep Japan's game sales chart in 33 years. GSMArena.com News: Weekly poll: Samsung Galaxy Z Fold3, the new S Pen and the Galaxy Z Flip3 - GSMArena.com news. Market Research Telecast News: How to import your WhatsApp chats to WhatsApp Plus 17.00 Heymods. Notebookcheck.net News: Realme will finally debut its first-gen laptop later in August 2021. NewsBytes: Redmi 10 officially teased; color options revealed. The Siasat Daily News: Xiaomi removes anti-lost mode from Mi Mix 4. Zee News: Good news for Motorola Razr owners! Smartphone is finally getting Android 11 update. EssentiallySports News: Animal Crossing: New Horizons- Predictions for the Next Big Update. Republic World News: Motorola Edge 20 price in India Leaked: Price to range between Rs 21,499 to Rs 29,999. Eurogamer.net News: Assassinations have been temporarily removed from Halo Infinite because "people just turn them off". EssentiallySports News: Call of Duty: Warzone- If You Can Win a Game Despite the Hackers, You Can See a Vanguard Teaser. Techradar News: Facebook Messenger voice and video calls are getting end-to-end encryption. Do you want to search again[Yes/No]? No