-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheadlines.py
44 lines (29 loc) · 1.22 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
import feedparser
from flask import Flask
from flask import render_template
from flask import request
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',
'ti': 'http://www.businessinsider.com/sai/rss',
'bi': 'http://uk.businessinsider.com/rss',
'fn': 'http://blog.foodnetwork.com/feed/',
'food': 'http://www.food.com/rss',
'med': 'https://medium.com/feed/@Medium',
'rs': 'http://www.rollingstone.com/rss',
'dlish': 'http://dish.allrecipes.com/feed/',
'hn' : 'https://news.ycombinator.com/rss'}
@app.route("/")
def get_news():
query = request.args.get("publication")
if not query or query.lower() not in RSS_FEEDS:
publication = "bbc"
else:
publication = query.lower()
feed = feedparser.parse(RSS_FEEDS[publication])
return render_template("home.html",articles=feed['entries'])
if __name__ == "__main__":
app.run(port=5000, debug=True)
# kool