-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (23 loc) · 659 Bytes
/
app.py
File metadata and controls
31 lines (23 loc) · 659 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from flask import Flask, render_template, request
import feedparser
app = Flask(__name__)
RSS_FEED = {
'bbc': "http://feeds.bbci.co.uk/news/rss.xml",
'cnn': 'http://rss.cnn.com/rss/edition.rss',
'fox': 'http://feeds.foxnews.com/foxnews/latest',
'iol': 'http://www.iol.co.za/cmlink/1.640'
}
@app.route("/")
def get_news():
query = request.args.get("publication")
if not query or query.lower() not in RSS_FEED:
publication = 'bbc'
else :
publication = query.lower()
feed = feedparser.parse(RSS_FEED[publication])
return render_template(
"home.html",
articles=feed['entries']
)
if __name__ == "__main__":
app.run()