/
app.py
34 lines (28 loc) · 816 Bytes
/
app.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
from flask import Flask, render_template
from bs4 import BeautifulSoup as bs
from splinter import Browser
import pandas as pd
from scrape_mars import scrape
import pymongo
app = Flask(__name__)
conn = 'mongodb://localhost:27017'
client = pymongo.MongoClient(conn)
db = client.mission_to_mars
# db.mars.drop()
# mars_dict = scrape()
# db.mars.insert_one(mars_dict)
# Set route
@app.route('/')
def index():
mars_page = db.mars.find_one()
return render_template('index.html', mars=mars_page)
@app.route('/launch')
def launch():
db.mars.drop()
mars_dict = scrape()
db.mars.insert_one(mars_dict)
mars_page = db.mars.find_one()
# Return the template with the teams list passed in
return render_template('index.html', mars=mars_page)
if __name__ == "__main__":
app.run(debug=True)