from flask_pymongo import PyMongo
from flask import Flask, render_template, redirect
import scrape_mars

app = Flask(__name__)

# Use flask_pymongo to set up mongo connection
app.config["MONGO_URI"] = "mongodb://localhost:27017/mission_to_mars_app"
mongodb = PyMongo(app)

# Create main page
@app.route("/")
def index():
    mars_data = mongo.db.mars_data.find_one()
    return render_template("index.html", data = mars_data)

# Create scrape page
@app.route("/scrape")
def scraper():
    mars_data = mongo.db.mars_data
    mars_item_data = scrape_mars.scrape()
    mars_data.update({}, mars_item_data, upsert=True)
    return redirect("/", code=302)

if __name__ == "__main__":
    app.run(debug=True)

from flask_pymongo import PyMongo
from flask import Flask, render_template, redirect
import scrape_mars

app = Flask(__name__)

# Use flask_pymongo to set up mongo connection
app.config["MONGO_URI"] = "mongodb://localhost:27017/mission_to_mars_app"
mongodb = PyMongo(app)

# Create main page
@app.route("/")
def index():
    mars_data = mongo.db.mars_data.find_one()
    return render_template("index.html", data = mars_data)

# Create scrape page
@app.route("/scrape")
def scraper():
    mars_data = mongo.db.mars_data
    mars_item_data = scrape_mars.scrape()
    mars_data.update({}, mars_item_data, upsert=True)
    return redirect("/", code=302)

if __name__ == "__main__":
    app.run(debug=True)

# Use flask_pymongo to set up mongo connection # Create main page # Create scrape page