-
Notifications
You must be signed in to change notification settings - Fork 17
/
app.py
52 lines (37 loc) · 1.04 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
import csv
from flask import Flask, render_template, request, redirect, url_for
import requests
from pager import Pager
def read_table(url):
"""Return a list of dict"""
# r = requests.get(url)
with open(url) as f:
return [row for row in csv.DictReader(f.readlines())]
APPNAME = "PrettyGalaxies"
STATIC_FOLDER = 'example'
TABLE_FILE = "example/fakecatalog.csv"
table = read_table(TABLE_FILE)
pager = Pager(len(table))
app = Flask(__name__, static_folder=STATIC_FOLDER)
app.config.update(
APPNAME=APPNAME,
)
@app.route('/')
def index():
return redirect('/0')
@app.route('/<int:ind>/')
def image_view(ind=None):
if ind >= pager.count:
return render_template("404.html"), 404
else:
pager.current = ind
return render_template(
'imageview.html',
index=ind,
pager=pager,
data=table[ind])
@app.route('/goto', methods=['POST', 'GET'])
def goto():
return redirect('/' + request.form['index'])
if __name__ == '__main__':
app.run(debug=True)