-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
36 lines (26 loc) · 832 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
35
36
import scrape_mars
import pymongo
from flask import Flask,jsonify,render_template,redirect
app = Flask(__name__)
@app.route("/")
def index():
# read data from mongodb
conn = 'mongodb://localhost:27017'
client = pymongo.MongoClient(conn)
db = client.marsDB
results = db.mars_data.find_one()
return render_template("index.html", listings = results)
#use data to populate index.html
@app.route("/scrape")
def scrape_rte():
scrape_data = scrape_mars.scrape()
conn = 'mongodb://localhost:27017'
client = pymongo.MongoClient(conn)
db = client.marsDB
lst = db.list_collection_names()
if "mars_data" in lst:
db.mars_data.delete_many({})
db.mars_data.insert_one(scrape_data)
return redirect("/")
if __name__ == "__main__":
app.run(debug=True)