-
Notifications
You must be signed in to change notification settings - Fork 0
/
app3.py
39 lines (27 loc) · 1.04 KB
/
app3.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
from flask import Flask, render_template, redirect
from flask_pymongo import PyMongo
import mars_data_scrape2
import sys
from dotenv import load_dotenv
import os
load_dotenv()
password = os.getenv('password')
flask_app = Flask(__name__)
mongo = PyMongo(flask_app, uri=f"mongodb+srv://patelpurvip:{password}@cluster0.bfrvo.mongodb.net/mars_app?retryWrites=true&w=majority")
@flask_app.route("/")
def index():
# return render_template("index.html", first_title=first_title, first_paragraph=first_paragraph)
collection_data = mongo.db.articles.find_one()
return render_template("index.html", stuff=collection_data)
@flask_app.route("/scrape/")
def scraper():
mars_data = mars_data_scrape2.scrape()
print(mars_data)
mongo.db.articles.update({}, mars_data, upsert=True)
return redirect("/", code=302)
@flask_app.route("/hemispheres")
def hemispheres():
collection_data = mongo.db.articles.find_one()
return render_template("hemispheres.html", stuff=collection_data)
if __name__ == "__main__":
flask_app.run(debug=True)