-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheadlines.py
More file actions
31 lines (24 loc) · 834 Bytes
/
headlines.py
File metadata and controls
31 lines (24 loc) · 834 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
import feedparser
from flask import Flask
app = Flask(__name__)
RSS_FEEDS = {'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("/")
@app.route("/<publication>")
def get_news(publication="bbc"):
feed = feedparser.parse(RSS_FEEDS[publication])
first_article = feed['entries'][0]
return """<html>
<body>
<h1>Headlines </h1>
<b>{0}</b> </ br>
<i>{1}</i> </ br>
<p>{2}</p> </ br>
</body>
</html>""".format(first_article.get("title"),
first_article.get("published"),
first_article.get("summary"))
if __name__ == "__main__":
app.run(port=5001, debug=True)