-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (35 loc) · 1.32 KB
/
main.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
import json
from flask import Flask, render_template
app = Flask(__name__)
f = open("data.json", "r")
data = json.load(f)
f.close()
categories = ["Endangered", "Critically Endangered", "Extinct in the Wild"]
plant_data = {
category : [plant for plant in data["Plants"] if plant["endangerment_status"] == category]
for category in categories
}
animal_data = {
category : [animal for animal in data["Animals"] if animal["endangerment_status"] == category]
for category in categories
}
@app.route("/")
def index():
return render_template("index.html")
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/plant-almanac")
def plant_almanac():
return render_template("plant_almanac.html", data=plant_data)
@app.route("/animal-almanac")
def animal_almanac():
return render_template("animal_almanac.html", data=animal_data)
@app.route("/plant/<plant_name>")
def plant(plant_name):
return render_template("plant.html", plant=[plant for plant in data["Plants"] if plant["name"] == plant_name.replace("-", " ")][0])
@app.route("/animal/<animal_name>")
def animal(animal_name):
return render_template("animal.html", animal=[animal for animal in data["Animals"] if animal["name"] == animal_name.replace("-", " ")][0])
if __name__ == "__main__":
app.run(debug=True, port=3000)