4 # Kot: a quote engine for TdCT
5 # Copyright (C) 2011 Paul Bazin
7 # This file is part of Kot.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 from random import choice
26 app = flask.Flask(__name__)
29 def __init__(self, content='', owner=''):
30 self.content = content
34 self.comments = list()
36 datafile = open('data.pkl', 'rb')
37 data = pickle.load(datafile)
43 listing.append({'id': kid, 'kot': data[kid], 'link':
44 flask.url_for('kot', kid=kid)})
50 listing.sort(reverse=True)
51 listing = listing if len(listing) < 20 else listing[:20]
53 ret.append({'id': kid, 'kot': data[kid], 'link':
54 flask.url_for('kot', kid=kid)})
57 def kots_list_random():
62 while i < 20 and len(listing) > 0:
63 item = choice(listing)
68 ret.append({'id': kid, 'kot': data[kid], 'link':
69 flask.url_for('kot', kid=kid)})
72 @app.route('/kot/<int:kid>')
74 return flask.render_template('kot.xhtml', kot=data[kid], kid=kid)
79 return flask.render_template('index.xhtml', kots=kots_list())
83 return flask.render_template('last.xhtml', kots=kots_list_last())
87 return flask.render_template('random.xhtml',
88 kots=kots_list_random())
90 if __name__ == '__main__':