-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
99 lines (74 loc) · 2.35 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# OMICRON TEAM - NFL APP
# IMPORT OF LIBRARIES ---------
from bson import json_util
import json
from flask import Flask, jsonify, render_template
import pymongo
from scrape_nfl import nfl_dict, stats_dict, bowl_dict
import os
# DEFINE DATABASE AND INSERT CURRENT DATA ---------
conn = os.environ.get('DATABASE_URL','')
#conn = "mongodb://localhost:27017"
client = pymongo.MongoClient(conn)
db = client.nfl_db
db.teams.drop()
db.stats.drop()
db.bowl.drop()
db.teams.insert_one(nfl_dict)
db.stats.insert_one(stats_dict)
db.bowl.insert_one(bowl_dict)
# ------------- FLASK APPLICATION -----------
app = Flask(__name__)
# HOME FUNCTION ----------
# Renderize the html pages
@app.route("/")
def home():
return render_template('index.html')
@app.route("/about")
def about():
return render_template('about.html')
@app.route("/charts")
def charts():
return render_template('charts.html')
@app.route("/conclusions")
def conclusions():
return render_template('conclusions.html')
@app.route("/predictions")
def predictions():
return render_template('predictions.html')
@app.route("/tables")
def tables():
return render_template('tables.html')
# CUSTOM TEAMS JSON HOSTING FUNCTION -------------
@app.route("/api/v1.0/teams")
def rendering_home():
conn = os.environ.get('DATABASE_URL','')
#conn = "mongodb://localhost:27017"
#client = pymongo.MongoClient(conn)
db = client.nfl_db
for i in db.teams.find():
return json.dumps(i, indent=4, default=json_util.default)
return jsonify(nfl_dict)
# CUSTOM 2020 STATS JSON HOSTING FUNCTION -------------
@app.route("/api/v1.0/stats")
def rendering_stats():
conn = os.environ.get('DATABASE_URL','')
#conn = "mongodb://localhost:27017"
client = pymongo.MongoClient(conn)
db = client.nfl_db
for i in db.stats.find():
return json.dumps(i, indent=4, default=json_util.default)
return jsonify(stats_dict)
# CUSTOM SUPERBOWL JSON HOSTING FUNCTION -------------
@app.route("/api/v1.0/bowl")
def rendering_bowl():
conn = os.environ.get('DATABASE_URL','')
#conn = "mongodb://localhost:27017"
client = pymongo.MongoClient(conn)
db = client.nfl_db
for i in db.bowl.find():
return json.dumps(i, indent=4, default=json_util.default)
return jsonify(bowl_dict)
# DEBUG FUNCTION ------------
if __name__ == "__main__":
app.run(debug=True)