From 690ee35228b1b7d431da999057fa4f4cf18ec036 Mon Sep 17 00:00:00 2001
From: Tanveer Hossain <thoss003@gold.ac.uk>
Date: Mon, 11 Feb 2019 22:39:33 +0000
Subject: [PATCH] lab-13

---
 lab-12/feeds.py                     | 12 ++++++++++++
 lab-12/templates/rss.html           |  3 ++-
 lab-12/templates/rss1.html          | 23 +++++++++++++++++++++++
 lab-13/headlines.py                 | 27 +++++++++++++++++++++++++++
 lab-13/templates/get_headlines.html | 20 ++++++++++++++++++++
 5 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100644 lab-12/feeds.py
 create mode 100644 lab-12/templates/rss1.html
 create mode 100644 lab-13/headlines.py
 create mode 100644 lab-13/templates/get_headlines.html

diff --git a/lab-12/feeds.py b/lab-12/feeds.py
new file mode 100644
index 0000000..a6790e7
--- /dev/null
+++ b/lab-12/feeds.py
@@ -0,0 +1,12 @@
+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)
diff --git a/lab-12/templates/rss.html b/lab-12/templates/rss.html
index 18d3dd7..600811b 100644
--- a/lab-12/templates/rss.html
+++ b/lab-12/templates/rss.html
@@ -1,4 +1,5 @@
-<html>
+< html>
+
 <body>
  <h1> BBC headline </h1>
     <b>{{articletitle}}</b> <br/>
diff --git a/lab-12/templates/rss1.html b/lab-12/templates/rss1.html
new file mode 100644
index 0000000..84ae99d
--- /dev/null
+++ b/lab-12/templates/rss1.html
@@ -0,0 +1,23 @@
+<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>
+-->
+
diff --git a/lab-13/headlines.py b/lab-13/headlines.py
new file mode 100644
index 0000000..eae20ad
--- /dev/null
+++ b/lab-13/headlines.py
@@ -0,0 +1,27 @@
+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)
diff --git a/lab-13/templates/get_headlines.html b/lab-13/templates/get_headlines.html
new file mode 100644
index 0000000..0be1902
--- /dev/null
+++ b/lab-13/templates/get_headlines.html
@@ -0,0 +1,20 @@
+<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>
-- 
GitLab