-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
31 lines (24 loc) · 919 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
from flask import Flask, render_template, jsonify, redirect
from flask_pymongo import PyMongo
import scrape_mars
#app = Flask(__name__)
app = Flask(__name__, template_folder='templates')
app.config["MONGO_URI"] = "mongodb://localhost:27017/mars_app"
mongo = PyMongo(app)
#mongo = PyMongo(app, uri=(f'mongodb+srv://YangLiu:[email protected]/test'))
#mongodb+srv://Yang_Liu:<password>@cluster0-kdojp.mongodb.net/test
#from pymongo import MongoClient
#client = MongoClient('mongodb://YangLiu:Asdfg12345@localhost:27017/prod-db')
#mongo = client['prod-db']
@app.route('/')
def index():
mars_data = mongo.db.mars.find_one()
return render_template("index.html", mars=mars_data)
@app.route('/scrape')
def fun():
mars = mongo.db.mars
mars_data = scrape_mars.scrape()
mars.update({},mars_data,upsert=True)
return redirect('/')
if __name__ == "__main__":
app.run(debug=True)