-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.py
91 lines (74 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# —— Modules
from flask import Flask, render_template, send_file #pylint: disable=import-error
from routes.utils import respond
from routes.search import search
from routes.add_book import sell
from routes.my_books import mybooks
from routes.delete import delete
# creating the flask app
app = Flask(__name__)
# —— API Routes
# • /
# serve the web app
@app.route('/')
def home():
return render_template('index.html', page = "home")
# • /listing
# list of books you are selling
@app.route('/listing')
def listing():
return render_template('index.html', page = "listing")
# • /new
# add a book to the market
@app.route('/new')
def new():
return render_template('index.html', page = "new")
# • /ping
# may be used to check the server
# status and/or response time
@app.route('/ping')
def ping():
return respond({'message': 'pong'})
# • /search?q={}
# search books in the
# bot's local database
@app.route('/search')
def _search():
return search()
# • /sell
# {isbn, price, init_data, web_app}
# search books in the
# bot's local database
@app.route('/sell', methods = ['POST'])
def _sell():
return sell()
# • /list
# {init_data, web_app}
# returns user's list of insertions.
@app.route('/list', methods = ['POST'])
def _list():
return mybooks()
# • /delete
# {init_data, web_app, insertion_id}
# remove an insertion by its row_id
@app.route('/delete', methods = ['POST'])
def _delete():
return delete()
# • /favicon.ico
# serve the website favicon
@app.route('/favicon.ico')
def favicon():
return send_file('static/web/favicon.ico')
# • /sw.js
# serve the service worker file (for PWAs)
@app.route('/sw.js')
def service_worker():
return send_file('static/web/sw.js')
# • /manifest.json
# manifest file (for PWAs)
@app.route('/manifest.json')
def manifest():
return send_file('static/web/manifest.json')
# —— Starting app
if __name__ == '__main__':
app.run()