-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
92 lines (77 loc) · 2.75 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
import app
from flask import Flask, render_template, request, flash, make_response, redirect, url_for
import requests
#import json
app = Flask(__name__)
WTF_CSRF_ENABLED = True
@app.route('/')
def home():
y = 0
title = ""
return render_template('home.html')
@app.route('/animal',methods=['POST'])
def animals():
name = request.form['species']
url = 'https://api.jsonbin.io/b/5b794f7a6376d24455a89004/9'
headers = {
'secret-key': '$2a$10$dKH7Mf31dIBNqbaH4Pcw4ucLNGMgr5ggMdBTBczssMZBsvNUyQePS'
}
r = requests.get(url, headers=headers)
if r.status_code == 200:
resp = r.json()
data = resp['features']
x = len(data)
y = 0
for i in range(0,x):
if name == data[i]['name']:
y = i
break
title = data[y]['name']
facts = data[y]['facts']
iframe = data[y]['iframe']
status = data[y]['status']
scientific_name = data[y]['scientific name']
habitat = data[y]['habitat']
places = data[y]['places']
matter = data[y]['matter']
pic_1 = data[y]['pic_1']
pic_2 = data[y]['pic_2']
pic_3 = data[y]['pic_3']
return render_template('index.html',title=title,facts=facts,iframe=iframe,status=status,scientific_name=scientific_name,habitat=habitat,places=places,matter=matter,pic_1=pic_1,pic_2=pic_2,pic_3=pic_3)
else:
#print("Error..")
return render_template('home.html')
@app.route('/species/<variable>')
def save(variable):
name = variable.strip()
url = 'https://api.jsonbin.io/b/5b794f7a6376d24455a89004/9'
headers = {
'secret-key': '$2a$10$dKH7Mf31dIBNqbaH4Pcw4ucLNGMgr5ggMdBTBczssMZBsvNUyQePS'
}
r = requests.get(url, headers=headers)
if r.status_code == 200:
resp = r.json()
data = resp['features']
x = len(data)
y = 0
for i in range(0,x):
if name == data[i]['name']:
y = i
break
title = data[y]['name']
facts = data[y]['facts']
iframe = data[y]['iframe']
status = data[y]['status']
scientific_name = data[y]['scientific name']
habitat = data[y]['habitat']
places = data[y]['places']
matter = data[y]['matter']
pic_1 = data[y]['pic_1']
pic_2 = data[y]['pic_2']
pic_3 = data[y]['pic_3']
return render_template('index.html',title=title,facts=facts,iframe=iframe,status=status,scientific_name=scientific_name,habitat=habitat,places=places,matter=matter,pic_1=pic_1,pic_2=pic_2,pic_3=pic_3)
else:
#print("Error..")
return render_template('home.html')
if __name__ == "__main__":
app.run(debug=True)