-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheadlines.py
32 lines (25 loc) · 910 Bytes
/
headlines.py
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
32
import feedparser
from flask import render_template
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'}
@app.route("/")
@app.route("/<publication>")
def get_news(publication="bbc"):
feed = feedparser.parse(RSS_FEEDS[publication])
return render_template("home.html", articles=feed['entries'])
if __name__ == "__main__":
app.run(port=5000, debug=True)
"""
def get_news(publication="bbc"):
feed = feedparser.parse(RSS_FEEDS[publication])
first_article = feed['entries'][0]
render_template("home.html",
title=first_article.get("title"),
published=first_article.get("published"),
summary=first_article.get("summary"))
if __name__ == "__main__":
app.run(port=5000, debug=True)
"""