~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to gozerplugs/web/quotes.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# web/quotes.py
2
 
#
3
 
#
4
 
 
5
 
""" show all quotes """
6
 
 
7
 
__copyright__ = 'this file is in the public domain'
8
 
 
9
 
 
10
 
from gozerbot.config import config
11
 
if config['dbenable']:
12
 
    from gozerbot.db import db
13
 
else:
14
 
    from gozerplugs.plugs.quote import quotes
15
 
from gozerplugs.plugs.webserver import httpd
16
 
 
17
 
def handle_quotes(event):
18
 
    """ show all pickled quotes """
19
 
    result = []
20
 
    for i in quotes.data:
21
 
        result.append("[%s] %s" % (i.id, i.txt))
22
 
    if not result:
23
 
        return ['no quotes', ]
24
 
    return result
25
 
 
26
 
def handle_quotesdb(event):
27
 
    """ show all database quotes """
28
 
    result = []
29
 
    dbresult = db.execute(""" SELECT indx, quote FROM quotes """)
30
 
    if not dbresult:
31
 
        return ['no quotes', ]
32
 
    for i in dbresult:
33
 
        result.append("[%s] %s" % (i[0], i[1]))
34
 
    return result
35
 
 
36
 
if httpd:
37
 
    if not config['dbenable']:
38
 
        httpd.addhandler('quotes', handle_quotes)
39
 
    else:
40
 
        httpd.addhandler('quotes', handle_quotesdb)