Flask Project Help | Creating News Web App Using Flask NewsAPI


Flask Web App

In this post, we have to create a web application using flask which takes news headlines, title, and description from NewsAPI.



Here Some Basic steps to do this


Open "News.org"

https://newsapi.org/


Then click on top of the menu item "documentation" and then install the "newsapi".




Installing Newsapi


Now new page is open, after this click on "python", which is on left sidebar:


Click on python and install news API




pip install newsapi-python

Now login(newsapi.org) to find API key


  • Login news api site and get api


Fill details and get api like this


937985d39a6144c382769fda00067b7d

Now create python project


NewsApiFlaskApp(project name)

Now in project directory create new directory “templates” and “app.py” file


File Structure:



app.py


#---------code---------#


from flask import Flask from newsapi import NewsApiClient app = Flask(__name__) @app.route('/') def index():     newsapi = NewsApiClient(api_key="937985d39a6144c382769fda00067b7d")     topheadlines = newsapi.get_top_headlines(sources = )


#------------------------------#


Now adding source:


See in the red circle:



Now new updated code after adding source


#------------------------------code-------------------


from flask import Flask from newsapi import NewsApiClient app = Flask(__name__) @app.route('/') def index():     newsapi = NewsApiClient(api_key="937985d39a6144c382769fda00067b7d")     topheadlines = newsapi.get_top_headlines(sources = "bbc-news")     article = topheadlines['article']     desc = []     news = []     img = []     for i in range(len(article)):         myarticles = article[i]         news.append(myarticles['title'])


#---------------------------------------------------------



Where title is take from: From newapi.org


See it in red rectangle


After this Go to the templates folder and create two file "index.html" and "bcc.html"




Thanks for reading this, if you need complete custom project then you can contact us at below Gmail:


codersarts@gmail.com

Send your requirements at this.


We are providing other project-related assignments like Java, PHP, C, C++, and more other help services, if you need any other programming help then also send your quote.


Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

Terms and Conditions        Privacy Policy    Pricing Policy       Refund Policy         COPYRIGHT © 2021

Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram