"""random_fact_scraper.py - Scrape the http://randomfactgenerator.net website."""

import os
import requests
from flask import Flask
from lxml import html

app = Flask(__name__)

@app.route("/")
def main():
    page = requests.get("http://randomfactgenerator.net")
    tree = html.fromstring(page.content)
    facts = tree.xpath("//div[@id='z']/text()")

    return list(filter(lambda x: x!= "\n\n", facts))


#-------------------------------------------------------------------------------
if __name__ == "__main__":
    port = int(os.environ.get("PORT", 5000))
    app.run(host='0.0.0.0', port=port)

"""random_fact_scraper.py - Scrape the http://randomfactgenerator.net website."""

import os
import json
import requests
from flask import Flask, Response
from lxml import html

app = Flask(__name__)

@app.route("/")
def main():
    page = requests.get("http://randomfactgenerator.net")
    tree = html.fromstring(page.content)
    facts = list(filter(lambda x: x!= "\n\n",
                 tree.xpath("//div[@id='z']/text()")))
    resp = Response(response=json.dumps(facts),
        status=200, \
        mimetype="application/json")

    # return list(filter(lambda x: x!= "\n\n", facts))
    return resp


#-------------------------------------------------------------------------------
if __name__ == "__main__":
    port = int(os.environ.get("PORT", 5000))
    app.run(host='0.0.0.0', port=port)

Return facts in JSON format.
[upd] Return facts in JSON format.

  """random_fact_scraper.py - Scrape the http://randomfactgenerator.net website."""
  
  import os
+ import json
  import requests
- from flask import Flask
+ from flask import Flask, Response
  from lxml import html
  
  app = Flask(__name__)
  
  @app.route("/")
  def main():
      page = requests.get("http://randomfactgenerator.net")
      tree = html.fromstring(page.content)
+     facts = list(filter(lambda x: x!= "\n\n",
-     facts = tree.xpath("//div[@id='z']/text()")
+                  tree.xpath("//div[@id='z']/text()")))
+     resp = Response(response=json.dumps(facts),
+         status=200, \
+         mimetype="application/json")
  
-     return list(filter(lambda x: x!= "\n\n", facts))
+     # return list(filter(lambda x: x!= "\n\n", facts))
+     return resp
  
  
  #-------------------------------------------------------------------------------
  if __name__ == "__main__":
      port = int(os.environ.get("PORT", 5000))
      app.run(host='0.0.0.0', port=port)
  
Return facts in JSON format.
## Code Before:
"""random_fact_scraper.py - Scrape the http://randomfactgenerator.net website."""

import os
import requests
from flask import Flask
from lxml import html

app = Flask(__name__)

@app.route("/")
def main():
    page = requests.get("http://randomfactgenerator.net")
    tree = html.fromstring(page.content)
    facts = tree.xpath("//div[@id='z']/text()")

    return list(filter(lambda x: x!= "\n\n", facts))


#-------------------------------------------------------------------------------
if __name__ == "__main__":
    port = int(os.environ.get("PORT", 5000))
    app.run(host='0.0.0.0', port=port)

## Instruction:
Return facts in JSON format.
## Code After:
"""random_fact_scraper.py - Scrape the http://randomfactgenerator.net website."""

import os
import json
import requests
from flask import Flask, Response
from lxml import html

app = Flask(__name__)

@app.route("/")
def main():
    page = requests.get("http://randomfactgenerator.net")
    tree = html.fromstring(page.content)
    facts = list(filter(lambda x: x!= "\n\n",
                 tree.xpath("//div[@id='z']/text()")))
    resp = Response(response=json.dumps(facts),
        status=200, \
        mimetype="application/json")

    # return list(filter(lambda x: x!= "\n\n", facts))
    return resp


#-------------------------------------------------------------------------------
if __name__ == "__main__":
    port = int(os.environ.get("PORT", 5000))
    app.run(host='0.0.0.0', port=port)
