From 798f3f27a2bbf13eb74354eb435d626168204d29 Mon Sep 17 00:00:00 2001 From: Paul Bazin Date: Wed, 24 Aug 2011 18:46:25 +0200 Subject: [PATCH] README added; made accessible --- README | 12 ++++++++++++ kot.py | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..5ef5ac2 --- /dev/null +++ b/README @@ -0,0 +1,12 @@ +This is Kot, a quote engine for TdCT. +Kot requires Python 2 and Flask. + +In order to run Kot, you just have to execute the script ‘kot.py’; then +Kot is made accessible through . + +Currently, the available pages are: +* : the root; currently similar to . +* : the index, all the quotes are listed there. +* : to briefly get the 20 last added quotes. +* : to briefly get 20 random quotes. +* : to get the quote with the given id. diff --git a/kot.py b/kot.py index f457f2a..50afcea 100755 --- a/kot.py +++ b/kot.py @@ -21,6 +21,7 @@ import flask import pickle +from random import choice app = flask.Flask(__name__) @@ -53,6 +54,21 @@ def kots_list_last(): flask.url_for('kot', kid=kid)}) return ret +def kots_list_random(): + ret = list() + listing = list(data) + work = list() + i = 0 + while i < 20 and len(listing) > 0: + item = choice(listing) + listing.remove(item) + work.append(item) + i += 1 + for kid in work: + ret.append({'id': kid, 'kot': data[kid], 'link': + flask.url_for('kot', kid=kid)}) + return ret + @app.route('/kot/') def kot(kid): return flask.render_template('kot.xhtml', kot=data[kid], kid=kid) @@ -66,5 +82,10 @@ def index(): def last(): return flask.render_template('last.xhtml', kots=kots_list_last()) +@app.route('/random') +def random(): + return flask.render_template('random.xhtml', + kots=kots_list_random()) + if __name__ == '__main__': app.run(debug=True) -- 2.1.4