# app.py
# https://medium.com/bitcraft/docker-composing-a-python-3-flask-app-line-by-line-93b721105777
import feedparser
from flask import Flask

app = Flask(__name__)

BBC_FEED = "http://feeds.bbci.co.uk/news/rss.xml"

'''
nginx is our web server. It will listen for web requests (which are generated by
our users visiting our web application using their browsers) and hand these requests over to our Flask application.
As our application is in Python, we also need WSGI (Web Server Gateway Interface).
This is a common interface between web servers and Python applications, which allows nginx to talk to Flask and vice versa.
'''


@app.route('/')
def get_news():
     feed = feedparser.parse(BBC_FEED)
     first_article = feed['entries'][0]
     return """<html>
       <body>
           <h1> BBC 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"))

@app.route('/<name>')
def hello_name(name):
    return "Hello {}!".format(name)

if __name__ == '__main__':
    app.run(host='0.0.0.0')
