Skip to content
Snippets Groups Projects
Commit 690ee352 authored by Tanveer Hossain's avatar Tanveer Hossain
Browse files

lab-13

parent 09a84e1f
Branches
No related merge requests found
from flask import Flask, render_template
import feedparser
app = Flask(__name__)
BBC_FEED = "http://feeds.bbci.co.uk/news/rss.xml"
@app.route("/")
def headline():
feed = feedparser.parse(BBC_FEED)
articles = feed['entries']
return render_template('rss.html', news=articles)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
<html>
< html>
<body>
<h1> BBC headline </h1>
<b>{{articletitle}}</b> <br/>
......
<body>
<form>
Publication:<br>
<input type="text" name="publisher">
</form>
{% for article in articles %}
{% if "the" in article.summary.lower() %}
<b>{{article.title}}</b><br />
<p>{{article.summary}}</p>
{% endif %}
{% endfor %}
<!--
<body>
<h1> BBC headline </h1>
<b>{{articletitle}}</b> <br/>
<i>{{published}}</i> <br/>
<p>{{summary}}</p> <br/>
</body>
-->
from flask import Flask, render_template
from flask import request
import feedparser
app = Flask(__name__)
RSS_FEEDS = { 'bbc': 'http://feeds.bbci.co.uk/news/rss.xml',
'aljazeera' : 'https://www.aljazeera.com/xml/rss/all.xml',
'ap':\
'http://hosted2.ap.org/atom/APDEFAULT/cae69a7523db45408eeb2b3a98c0c9c5'}
@app.route("/")
def headlines():
publication =''
if request.args.get('publication'):
publication = request.args.get('publication')
if not publication or publication.lower() not in RSS_FEEDS:
publication = "bbc"
else:
publication = publication.lower()
feed = feedparser.parse(RSS_FEEDS[publication])
articles = feed['entries']
return render_template('get_headlines.html',articles=articles)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
<html>
<head>
<title>Headlines</title>
</head>
<body>
<h1>Headlines</h1>
<form>
<input type="text" name="publication" placeholder="search for headlines" />
<input type="submit" value="Submit" />
</form>
{% for article in articles %}
<b>{{article.title}}</b><br />
<i>{{article.published}}</i><br />
<p>{{article.summary}}</p>
<hr />
{% endfor %}
</body>
</html>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment