-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.py
50 lines (36 loc) · 1.29 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Import Dependencies
from flask import Flask, render_template, redirect
from flask_pymongo import PyMongo
import scrape_mars
import os
# Hidden authetication file
#import config
# Create an instance of Flask app
app = Flask(__name__)
#Use flask_pymongo to set up connection through mLab
app.config["MONGO_URI"] = os.environ.get('authentication')
mongo = PyMongo(app)
# Use flask_pymongo to set up mongo connection locally
# app.config["MONGO_URI"] = "mongodb://localhost:27017/mars_app"
# mongo = PyMongo(app)
# Create route that renders index.html template and finds documents from mongo
@app.route("/")
def home():
# Find data
mars_info = mongo.db.mars_info.find_one()
# Return template and data
return render_template("index.html", mars_info=mars_info)
# Route that will trigger scrape function
@app.route("/scrape")
def scrape():
# Run scrapped functions
mars_info = mongo.db.mars_info
mars_data = scrape_mars.scrape_mars_news()
mars_data = scrape_mars.scrape_mars_image()
mars_data = scrape_mars.scrape_mars_facts()
mars_data = scrape_mars.scrape_mars_weather()
mars_data = scrape_mars.scrape_mars_hemispheres()
mars_info.update({}, mars_data, upsert=True)
return redirect("/", code=302)
if __name__ == "__main__":
app.run(debug= True)