-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
69 lines (55 loc) · 1.91 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
from werkzeug.exceptions import RequestURITooLarge
from server import find_all_products_data, find_product_data
from db_manager import save_to_db
from flask import Flask, url_for, request, redirect, render_template
import os
from talk import add_comment_to_db, get_all_posts
app = Flask(__name__)
key = os.environ.get('KEY')
app.config['SECRET_KEY'] = key
@app.route('/', methods=['GET'])
def index():
try:
return render_template('index.html')
except:
return redirect('/error')
@app.route('/error', methods=['GET'])
def error():
return render_template('error.html')
@app.route('/api/find-all/<string:product>', methods=['GET'])
def api_find_all(product):
product_to_search = product.replace(' ', '-')
return find_all_products_data(product_to_search)
@app.route('/api/find/<string:product2>', methods=['GET'])
def api_find_product(product2):
product_to_search2 = product2.replace(' ', '-')
return find_product_data(product_to_search2)
@app.route('/search', methods=['GET', 'POST'])
def api_search():
try:
if request.method == 'POST':
p = request.form['proc']
return redirect(f'/api/find-all/{p}')
else:
return redirect('/error')
except:
return redirect('/error')
@app.route('/api/save/<string:product>/<int:p_id>/<string:email>/<string:email_provider>', methods=['GET', 'POST'])
def save_product(product, p_id, email, email_provider):
return save_to_db(product, p_id, email, email_provider)
@app.route('/talk', methods=['GET', 'POST'])
def talk():
if request.method == 'POST':
p_content = request.form['txt']
author = request.form['op']
title = request.form['title']
add_comment_to_db(author, p_content, title)
else:
pass
posts = get_all_posts()
return render_template(
'talk.html',
posts = posts
)
if __name__ == '__main__':
app.run(debug=True)